Bug 3098 - mettre à jour les graphiques montrant l'évolution du cluster
- improved readability by adding a color spacing between labs to help to easily identify all wners of the same group
This commit is contained in:
		
							parent
							
								
									08ac2506ae
								
							
						
					
					
						commit
						939ecda69d
					
				|  | @ -135,26 +135,46 @@ def stackplot(ax, x_signal, y_signals, legend_location='best'): | ||||||
|         ax.stackplot(x_signal, list(y_signals.values())) |         ax.stackplot(x_signal, list(y_signals.values())) | ||||||
|         plt.legend(list(y_signals.keys())) |         plt.legend(list(y_signals.keys())) | ||||||
|     else: |     else: | ||||||
|         # emulating missing Axes.stackplot method |  | ||||||
|         colors = get_rgb_palette(num_colors=len(y_signals), saturation=1.0, value=0.8)  # ['blue', 'orange', 'green', 'purple', 'yellow', 'cyan'] |  | ||||||
| 
 | 
 | ||||||
|         # we sort the signals according to their labels to group departments of the same lab together on the plot |         # we sort the signals according to their labels to group departments of the same lab together on the plot | ||||||
|         ordered_y_signals = [] |         ordered_y_signals = [] | ||||||
|         ordered_labels = [] |         ordered_labels = [] | ||||||
|  |         labs = set() | ||||||
|  |         owner_to_lab = {} | ||||||
|         for label, y_signal in sorted(y_signals.items()): |         for label, y_signal in sorted(y_signals.items()): | ||||||
|             ordered_y_signals.append(y_signal) |             ordered_y_signals.append(y_signal) | ||||||
|             ordered_labels.append(label) |             ordered_labels.append(label) | ||||||
|  |             lab = label.split('.')[0] | ||||||
|  |             labs.add(lab) | ||||||
|  |             owner_to_lab[label] = lab | ||||||
|  | 
 | ||||||
|  |         # instead of evenly spreading the colour in the spectrum, we try to separate groups of colors (1 group for a lab), to ease reading the graph | ||||||
|  |         num_unused_colors_between_labs = 1 | ||||||
|  |         num_unused_colors = len(labs) * num_unused_colors_between_labs | ||||||
|  |         num_owners = len(y_signals) | ||||||
|  |         num_colors = num_owners + num_unused_colors | ||||||
|  |         # emulating missing Axes.stackplot method | ||||||
|  |         colors = get_rgb_palette(num_colors=num_colors, saturation=1.0, value=0.8)  # ['blue', 'orange', 'green', 'purple', 'yellow', 'cyan'] | ||||||
|  | 
 | ||||||
|         y = np.row_stack(ordered_y_signals) |         y = np.row_stack(ordered_y_signals) | ||||||
|         # this call to 'cumsum' (cumulative sum), passing in your y data, |         # this call to 'cumsum' (cumulative sum), passing in your y data, | ||||||
|         # is necessary to avoid having to manually order the datasets |         # is necessary to avoid having to manually order the datasets | ||||||
|         y_stack = np.cumsum(y, axis=0)   # a 3x10 array |         y_stack = np.cumsum(y, axis=0)   # a 3x10 array | ||||||
|  |         last_lab = None | ||||||
|  |         color_index = 0 | ||||||
|         for series_index in range(len(y_signals)): |         for series_index in range(len(y_signals)): | ||||||
|             if series_index == 0: |             if series_index == 0: | ||||||
|                 from_signal = 0 |                 from_signal = 0 | ||||||
|             else: |             else: | ||||||
|                 from_signal = y_stack[series_index - 1, :] |                 from_signal = y_stack[series_index - 1, :] | ||||||
|             ax.fill_between(x_signal, from_signal, y_stack[series_index, :], color=colors[series_index], lw=0.0) |             owner = ordered_labels[series_index] | ||||||
|             p = plt.Rectangle((0, 0), 0, 0, color=colors[series_index]) |             lab = owner_to_lab[owner] | ||||||
|  |             color_index = (color_index + 1) % num_colors | ||||||
|  |             if lab != last_lab: | ||||||
|  |                 color_index = (color_index + num_unused_colors_between_labs) % num_colors | ||||||
|  |                 last_lab = lab | ||||||
|  |             ax.fill_between(x_signal, from_signal, y_stack[series_index, :], color=colors[color_index], lw=0.0) | ||||||
|  |             p = plt.Rectangle((0, 0), 0, 0, color=colors[color_index]) | ||||||
|             ax.add_patch(p) |             ax.add_patch(p) | ||||||
| 
 | 
 | ||||||
|         if legend_location == 'outside right': |         if legend_location == 'outside right': | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue