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