From 344fe2f9082fbade7fcfda962f78349d04f28495 Mon Sep 17 00:00:00 2001 From: Dominik Mehlem Date: Tue, 17 Oct 2023 10:14:59 +0200 Subject: [PATCH] add consistent coloring of labels --- src/rdplot/SimulationDataItem.py | 2 +- src/rdplot/Widgets/PlotWidget.py | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/rdplot/SimulationDataItem.py b/src/rdplot/SimulationDataItem.py index e580799..680f6f0 100644 --- a/src/rdplot/SimulationDataItem.py +++ b/src/rdplot/SimulationDataItem.py @@ -27,6 +27,7 @@ from PyQt5.QtCore import * from PyQt5.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QComboBox, QPushButton, QDialogButtonBox, QLabel, QCheckBox, QGroupBox, QMessageBox, QApplication import re +#from rdplot.Widgets.PlotWidget import color_dict # @@ -502,7 +503,6 @@ def parse_csv_item_list(self, log_path): # in order to determine the type try: from rdplot.SimulationDataItemClasses.CsvLogs import CSVLog - with open(log_path) as csvfile: lines = csvfile.readlines() diff --git a/src/rdplot/Widgets/PlotWidget.py b/src/rdplot/Widgets/PlotWidget.py index c682f08..f50d7fb 100644 --- a/src/rdplot/Widgets/PlotWidget.py +++ b/src/rdplot/Widgets/PlotWidget.py @@ -45,6 +45,9 @@ import pkg_resources +color_dict = {} +color_marker_array = [['r', 'x'], ['b', 'x'], ['y', 'x'], ['k', 'x'], ['c', 'x'], ['m', 'x'], ['g', 'x'], ['r', 'o'], ['b', 'o'], ['y', 'o'], ['k', 'o'], ['c', 'o'], ['m', 'o'], ['g', 'o']] + Ui_name = pkg_resources.resource_filename('rdplot', 'ui' + sep + 'plotWidget.ui') Ui_PlotWidget, QWidget = loadUiType(Ui_name) @@ -144,8 +147,6 @@ def change_plot(self, plot_data_collection, user_generated_curves=False): self.ax.clear() self.ax.grid(True) - self.ax.set_prop_cycle(cycler('color', ['r', 'b', 'y', 'k', 'c', 'm', 'g', 'r', 'b', 'y', 'k', 'c', 'm', 'g']) + - cycler('marker', ['x', 'x', 'x', 'x', 'x', 'x', 'x', 'o', 'o', 'o', 'o', 'o', 'o', 'o'])) self.ax.set_xlabel(plot_data_collection[0].label[0]) self.ax.set_ylabel(plot_data_collection[0].label[1]) @@ -181,7 +182,8 @@ def change_plot(self, plot_data_collection, user_generated_curves=False): for plot_data in plot_data_collection: # Create legend from variable path and sim data items identifiers l = legend[plot_count] #" ".join([i for i in plot_data.identifiers] + plot_data.path) - + if legend[plot_count] not in color_dict: + color_dict[legend[plot_count]] = color_marker_array[len(color_dict) % len(color_marker_array)] # Convert list of pairs of strings to two sorted lists of floats # Check if plot_data value has a confidence interval # Confidence intervals are stored in tuples with three entries @@ -193,7 +195,7 @@ def change_plot(self, plot_data_collection, user_generated_curves=False): [xs, ys] = list(zip(*sorted_value_pairs)) # plot the current plot data - curve = self.ax.plot(xs, ys, label=l) + curve = self.ax.plot(xs, ys, label=l, color=color_dict[legend[plot_count]][0], marker=color_dict[legend[plot_count]][1]) plot_count += 1 else: @@ -212,17 +214,17 @@ def change_plot(self, plot_data_collection, user_generated_curves=False): anchor_index = 1 if not user_generated_curves else 0 if self.ci_mode == 'average': - curve = self.ax.plot(xs, ys, label=l) + curve = self.ax.plot(xs, ys, label=l, color=color_dict[legend[plot_count]]) elif self.ci_mode == 'best': if plot_data.identifiers[anchor_index] == self.anchor_identifier: - curve = self.ax.plot(xs, ys_low, label=l) + curve = self.ax.plot(xs, ys_low, label=l, color=color_dict[legend[plot_count]]) else: - curve = self.ax.plot(xs, ys_up, label=l) + curve = self.ax.plot(xs, ys_up, label=l, color=color_dict[legend[plot_count]]) elif self.ci_mode == 'worst': if plot_data.identifiers[anchor_index] == self.anchor_identifier: - curve = self.ax.plot(xs, ys_up, label=l) + curve = self.ax.plot(xs, ys_up, label=l, color=color_dict[legend[plot_count]]) else: - curve = self.ax.plot(xs, ys_low, label=l) + curve = self.ax.plot(xs, ys_low, label=l, color=color_dict[legend[plot_count]]) # plot the ci as polygon around the current curve poly_ci = self.ax.fill(xs_ci, ys_ci, c=curve[0].get_c(), ec=curve[0].get_c(), alpha=0.3)