Stack Overflow Asked by fgg1991 on December 10, 2020
Here is what I did in PyQt with QtChart:
I have 3 columns in a dataframe, col1
is used as y-axis value, col2
is used as x-axis value. BUT col3
is used as x-axis label.
Each point has three attributes:SimErr(y)
, GID(integer, x axis)
and Group(shown in x-axis label)
So how could I do this in matplotlib? I cannot find any class which is similar to QCatogoryAxis
in QT
Here is my pyqt code:
gaugefile = list(self.gaugefile_dict.values())[0] # this is the dataframe
# this dict stores the start GID and end GID for each Group
# Like axis_init_dict[(0, 100)] = GroupA
# axis_init_dict[(101, 200)] = GroupB
axis_init_dict = extract_start_end_for_group(gaugefile)
x_axis_group = QtCharts.QCategoryAxis()
x_axis_group.setMin(int(list(axis_init_dict.keys())[0][0]))
x_axis_group.setMax(int(list(axis_init_dict.keys())[-1][0]))
for (start, end), group in axis_init_dict.items():
x_axis_group.append(str(group), end)
x_axis_group.setTitleText(self.x_label)
x_axis_group.setLabelsAngle(-90)
y_axis_value = QtCharts.QValueAxis()
y_axis_value.setTitleText(self.y_label)
y_axis_value.setRange(self.axis_range['y_min'], self.axis_range['y_max'])
chart.addAxis(x_axis_group, Qt.AlignBottom)
chart.addAxis(y_axis_value, Qt.AlignLeft)
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP