From 08ac2506aebc9aa473049c61993c3636db56af8e Mon Sep 17 00:00:00 2001 From: Guillaume Raffy Date: Tue, 23 Feb 2021 15:57:54 +0000 Subject: [PATCH] =?UTF-8?q?Bug=203098=20-=20mettre=20=C3=A0=20jour=20les?= =?UTF-8?q?=20graphiques=20montrant=20l'=C3=A9volution=20du=20cluster?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - improved readability by ordering owners; as a result, owners of the same lab are no longer separated --- cluster_stats.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cluster_stats.py b/cluster_stats.py index 047b2fd..4a19ec2 100644 --- a/cluster_stats.py +++ b/cluster_stats.py @@ -137,7 +137,14 @@ def stackplot(ax, x_signal, y_signals, legend_location='best'): 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'] - y = np.row_stack(list(y_signals.itervalues())) + + # we sort the signals according to their labels to group departments of the same lab together on the plot + ordered_y_signals = [] + ordered_labels = [] + for label, y_signal in sorted(y_signals.items()): + ordered_y_signals.append(y_signal) + ordered_labels.append(label) + y = np.row_stack(ordered_y_signals) # this call to 'cumsum' (cumulative sum), passing in your y data, # is necessary to avoid having to manually order the datasets y_stack = np.cumsum(y, axis=0) # a 3x10 array @@ -151,9 +158,9 @@ def stackplot(ax, x_signal, y_signals, legend_location='best'): ax.add_patch(p) if legend_location == 'outside right': - plt.legend(list(y_signals.keys()), bbox_to_anchor=(1.10, 1.00), loc='upper left') # force the legend into the bounding box + plt.legend(ordered_labels, bbox_to_anchor=(1.10, 1.00), loc='upper left') # force the legend into the bounding box else: - plt.legend(list(y_signals.keys()), loc=legend_location) + plt.legend(ordered_labels, loc=legend_location) def draw_cluster_value_over_time_graph(inventory, from_date, to_date, graph_type): @@ -223,7 +230,6 @@ def draw_cluster_value_over_time_graph(inventory, from_date, to_date, graph_type ax.xaxis.set_major_formatter(yearsFmt) ax.xaxis.set_minor_locator(months) - # rotates and right aligns the x labels, and moves the bottom of the # axes up to make room for them # fig.autofmt_xdate()