Skip to content

Commit

Permalink
add consistent coloring of labels
Browse files Browse the repository at this point in the history
  • Loading branch information
dmehlem committed Oct 17, 2023
1 parent a23cb51 commit 344fe2f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/rdplot/SimulationDataItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


#
Expand Down Expand Up @@ -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()

Expand Down
20 changes: 11 additions & 9 deletions src/rdplot/Widgets/PlotWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit 344fe2f

Please sign in to comment.