I am building a PyQt4 GUI with embedded Matplotlib (1.4.3). It lets a user select from a list of available parameters to plot & gives them control to add/remove, rescale subplots etc. to send their data to. Anyway, I came across this behavior of add_subplot
followed by change_geometry
that I didn't expect.
Make a subplot in the 2,1,2 position:
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 10, 0.1)
y1 = 0.05 * x**2
y2 = -1 *y1
figure = plt.figure()
ax1 = figure.add_subplot(2,1,2,label='sub2')
ax1.plot(x, y1, 'g-')
plt.show()
That was a mistake lets change it to subplot #1 and relabel
ax1.change_geometry(2,1,1)
ax1.set_label('sub1')
Ok, Now lets add subplot 2 for real this time...
ax2 = figure.add_subplot(2,1,2,label='sub2')
ax2.plot(x, y2, 'b-')
plt.draw()
Wait a minute it plotted on Subplot 1 ... and where is my subplot 2? Lets look at ax1, and ax2
ax1
<matplotlib.axes._subplots.AxesSubplot at 0xcaa32b0>
ax2
<matplotlib.axes._subplots.AxesSubplot at 0xcaa32b0>
They are the same axes? So after some digging I came across This GitHub Issue 429 and it says it is fixed ... but it doesn't look like it to me. Am I missing something or is this really still an issue?
matplotlib.pyplot
instead I importFigure
andFigureCanvasQTAgg
... but the behavior is the same either way. – Aero Engy