【发布时间】:2016-07-29 15:39:57
【问题描述】:
我正在向画布添加一个 matplotlib 图,以便我可以将它与我的应用程序中的 pyqt 集成。我环顾四周并使用plt.add_subplot(111) 似乎是要走的路(?)但我不能像使用“普通”情节一样向子情节添加任何属性
人物设置
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 画布中绘制图形,而不使用子图,以便我可以从我的图的更多属性中受益。
【问题讨论】:
标签: python matplotlib