I have an application that have 3 figures, and dynamicaly change them. For now it's been working fine by using add_subplot()
to the figure. But now I have to make my graphs more complex, and need to use subplot2grid()
self.figure1 = plt.figure()
self.canvas1 = FigureCanvas(self.figure1)
self.graphtoolbar1 = NavigationToolbar(self.canvas1, frameGraph1)
self.figure3 = plt.figure()
self.canvas3 = FigureCanvas(self.figure3)
self.graphtoolbar3 = NavigationToolbar(self.canvas3, frameGraph3)
self.figure4 = plt.figure()
self.canvas4 = FigureCanvas(self.figure4)
self.graphtoolbar4 = NavigationToolbar(self.canvas4, frameGraph4)
And here's the code that adds it, and what I've got so far.
#ax = self.figure1.add_subplot(2,1,1) <---- What I used to do
fig = self.figure1
ax = plt.subplot2grid((4,4), (0,0), rowspan=3, colspan=4) # <--- what I'm trying to do
ax.hold(False)
ax.plot(df['Close'], 'b-')
ax.legend(loc=0)
ax.set_xlabel("Date")
ax.set_ylabel("Price")
ax.grid(True)
for tick in ax.get_xticklabels():
tick.set_rotation(20)
self.canvas1.draw()
The above adds it to figure 4. Probably because that's the latest instantiated by plt. But I'd like the above to add a subplot2grid to self.figure1
, while still having the dynamicly abilities as before.