Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

figure doesn't reflect artist object's axes change #430

Closed
c00kiemonster opened this Issue · 3 comments

2 participants

@c00kiemonster

When I run the code below the two plots are still in two separate subplots, when in fact one of them has had its axes changed to the other one. Shouldn't both be shown in the same axes in the figure since they both share the same axes object?

import matplotlib.pyplot as plt

fig = plt.figure()  
ax_1 = fig.add_subplot(2,1,1)
ax_2 = fig.add_subplot(2,1,2)
ax_1.plot([0,1,2],[0,1,2])
ax_2.plot([0,1,2],[2,1,0])

print 'before'
for line in ax_1.get_lines():
    print line.get_ydata()
    print line.get_axes().get_geometry()
    print id(line.get_axes())

for line in ax_2.get_lines():
    print line.get_ydata()
    print line.get_axes().get_geometry()
    print id(line.get_axes())

f = ax_2.get_lines()[0]
f.set_axes(ax_1)

print 'after'
for line in ax_1.get_lines():
    print line.get_ydata()
    print line.get_axes().get_geometry()
    print id(line.get_axes())

for line in ax_2.get_lines():
    print line.get_ydata()
    print line.get_axes().get_geometry()
    print id(line.get_axes())

plt.show()
@leejjoon
Owner

No. Matplotlib works somewhat differently. What is more relevant is the transform attribute of the artist.

f.set_transform(ax_1.transData)
f.set_clip_on(False)

You need to turn off clipping (or set the clipping box appropriately) because f is still clipped by bounding box of ax_1.

In general, things can be more complicated, and moving an artist from one to other axes is not supported yet.

@leejjoon
Owner

I must have said

You need to turn off clipping (or set the clipping box appropriately) because f is still clipped by bounding box of ax_2.

@c00kiemonster

Yea I suspected it was a simple case of it not being supported. Thanks for the reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.