2

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()

enter image description here 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?

9
  • What version of matplotlib are you using? Your example works fine for me in 1.4.3 Commented Jul 24, 2015 at 15:23
  • As stated above I am using 1.4.3. So at the end you have 2 separate subplots? I have tired it on 2 different machines (one with 1.4.3 and one with 1.4.2) both in an Ipython console & regular Python3 (using anaconda) and I get the results shown in the picture above ... strange. Commented Jul 24, 2015 at 15:56
  • Ah, sorry, I just missed the version in the question. Yes, I get two separate subplots when I try it. Hmm. Are you doing it interactively or in a script? Commented Jul 24, 2015 at 16:04
  • Ok, well, you are right, this is strange. When I put the whole code into a single cell I duplicate your results. When I first tried it I just typed things into ipython one line at a time and it worked fine. Hmmm.... Commented Jul 24, 2015 at 16:12
  • My original issue was in a PyQT4 GUI application were the user can manipulate/move/add subplots. Occasionally with the right steps of add/remove etc. I would get a line plotted on the wrong axes and a missing subplot. The full application was to long to post here so I cut it down to a small example to demonstrate the issue. The only real difference in my PyQT app is that I don't use matplotlib.pyplot instead I import Figure and FigureCanvasQTAgg ... but the behavior is the same either way. Commented Jul 24, 2015 at 17:18

1 Answer 1

1

I create this as an issue on Github. It was confirmed and added to the next point release milestone.

GitHub Issue 4786

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.