-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubTabs.py
76 lines (66 loc) · 3.91 KB
/
SubTabs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from PySide6.QtWidgets import QWidget, QTabWidget, QVBoxLayout
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg
from matplotlib.backends.backend_qtagg import NavigationToolbar2QT
from typing import List
import matplotlib.figure
from PlotTreeItems import PlottableItem
from PlotModifiers import PlotModifier, ModifierLinecolor, ModifierLinestyle, ModifierColormap
import numpy as np
class SubTabs(QTabWidget):
def __init__(self, datacollector, tabitem):
super().__init__()
self.datacollector = datacollector
self.figures: List[matplotlib.figure] = []
# iterate through subtabs
for i in range(tabitem.childCount()):
#add subtabs
subtab_widget = QWidget()
subtab = self.addTab(QWidget(), tabitem.child(i).text(0))
#add subplots
layout = QVBoxLayout()
figure = matplotlib.figure.Figure(figsize=(5, 5))
canvas = FigureCanvasQTAgg(figure)
layout.addWidget(canvas)
layout.addWidget(NavigationToolbar2QT(canvas))
subplot_count = tabitem.child(i).childCount()
ax = figure.subplots(subplot_count)
if subplot_count <= 1:
ax = [ax]
# iterate through subplots
for j in range(subplot_count):
ax[j].set_title(str(tabitem.child(i).child(j).text(0)))
ax[j].set_xscale('log')
# iterate through plottables and plot modifiers
for k in range(tabitem.child(i).child(j).childCount()):
plottable_or_modifier_item = tabitem.child(i).child(j).child(k).data(0, 1)
if isinstance(plottable_or_modifier_item, PlottableItem):
plottable = plottable_or_modifier_item
dataset = self.datacollector.get_data_id(plottable_or_modifier_item.get_data_id())
if plottable.type_num == 1: #data plot: log-log plot, show only data
ax[j].plot(dataset.get_x_data(), dataset.get_y_data())
ax[j].set_yscale('log')
elif plottable.type_num == 2: #fit plot: log-log plot, show fit and data curve
ax[j].plot(dataset.get_x_data(), dataset.get_y_data())
ax[j].plot(dataset.get_x_data(), dataset.get_y_fit())
ax[j].set_yscale('log')
elif plottable.type_num == 3: #residual plot lin-log plot, show calc and show res only
ax[j].plot(dataset.get_x_data(), np.subtract(dataset.get_y_fit(), dataset.get_y_data()))
# iterate through plottable modifier, e.g. linecolor, linestyle
for l in range(plottable.childCount()):
plottable_modifier = plottable.child(l)
if isinstance(plottable_modifier.data(0, 1), ModifierLinecolor):
ax[j].get_lines()[-1].set_color(plottable_modifier.text(0).split('=')[1])
elif isinstance(plottable_modifier.data(0, 1), ModifierLinestyle):
ax[j].get_lines()[-1].set_linestyle(plottable_modifier.text(0).split('=')[1])
elif isinstance(plottable_or_modifier_item, PlotModifier):
plot_modifier = plottable_or_modifier_item
if isinstance(plot_modifier, ModifierColormap):
cmap = matplotlib.colormaps[plot_modifier.text(0).split('=')[1]]
n = len(ax[j].get_lines())
for m in range(n):
ax[j].get_lines()[m].set_color(cmap(m/(n-1)))
figure.tight_layout()
self.widget(i).setLayout(layout)
self.figures.append(figure)
def get_fitpage_index(self):
return self.fitpage_index