2
我将一个matplotlib图添加到画布上,以便我可以将它与pyqt整合到我的应用程序中。我正在四处寻找并使用plt.add_subplot(111)
似乎是要走的路(?),但我不能把任何属性的插曲,因为我可以用“普通”的情节matplotlib和subplots属性
人物设置
self.figure1 = plt.figure()
self.canvas1 = FigureCanvas(self.figure1)
self.graphtoolbar1 = NavigationToolbar(self.canvas1, frameGraph1)
hboxlayout = qt.QVBoxLayout()
hboxlayout.addWidget(self.graphtoolbar1)
hboxlayout.addWidget(self.canvas1)
frameGraph1.setLayout(hboxlayout)
创造插曲添加并增加数据
df = self.quandl.getData(startDate, endDate, company)
ax = self.figure1.add_subplot(111)
ax.hold(False)
ax.plot(df['Close'], 'b-')
ax.legend(loc=0)
ax.grid(True)
我想设置x和y的标签,但如果我不ax.xlabel("Test")
AttributeError: 'AxesSubplot' object has no attribute 'ylabel'
,如果我这样做是不使用的插曲
这是可能的plt.figure(figsize=(7, 4))
plt.plot(df['Close'], 'k-')
plt.grid(True)
plt.legend(loc=0)
plt.xlabel('value')
plt.ylabel('frequency')
plt.title('Histogram')
locs, labels = plt.xticks()
plt.setp(labels, rotation=25)
plt.show()
所以我想我的问题是,是不是可以进一步修改次要情节?或者是否可以在Pyqt画布上绘制图表,而不使用子图,这样我可以从我的图中获得更多属性。
这样做的伎俩,谢谢!是否可以旋转x标签? – vandelay
@vandelay当然。你可以使用'rotation' kwarg:'plt.xlabel('X Axis',rotation = 30)' – Suever
我更喜欢用subplots :)和ax一样。谢谢回答。 – vandelay