Copying collections over to a new figure

Hello,

In the following example, I am trying to copy over existing collections from one plot to another:

import matplotlib.pyplot as mpl

fig = mpl.figure()
ax1 = fig.add_subplot(1,1,1)
ax1.scatter([0.5],[0.5])
fig.savefig('test1.png')

fig = mpl.figure()
ax2 = fig.add_subplot(1,1,1)
for c in ax1.collections:
    ax2.add_collection(c)
fig.savefig('test2.png')

However, the circle appears in the wrong place in test2.png (close to 0.4, 0.4 instead of 0.5,0.5). Is it not possible/safe to copy over collections in this way? If not, then how should this be done?

Thanks,

Thomas

As far as I can say, moving around artists from one axes to the other
is NOT recommended. And I encourage you to create separate artists for
each axes rather than try to reuse the existing ones.

For your particular example,

fig = mpl.figure()
ax2 = fig.add_subplot(1,1,1)
for c in ax1.collections:
    c._transOffset=ax2.transData
    ax2.add_collection(c)

should work.

Regards,

-JJ

···

On Mon, Mar 29, 2010 at 12:24 PM, Thomas Robitaille <thomas.robitaille@...287...> wrote:

Hello,

In the following example, I am trying to copy over existing collections from one plot to another:

import matplotlib.pyplot as mpl

fig = mpl.figure()
ax1 = fig.add_subplot(1,1,1)
ax1.scatter([0.5],[0.5])
fig.savefig('test1.png')

fig = mpl.figure()
ax2 = fig.add_subplot(1,1,1)
for c in ax1.collections:
ax2.add_collection(c)
fig.savefig('test2.png')

However, the circle appears in the wrong place in test2.png (close to 0.4, 0.4 instead of 0.5,0.5). Is it not possible/safe to copy over collections in this way? If not, then how should this be done?

Thanks,

Thomas
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Hi Jae-Joon,

Thanks for your quick reply! Since for example LineCollections can be created independent of the Axes in which they are going to be plotted through the creation of a LineCollection instance, would it not be possible to have a method that allows one to retrieve an Axes-independent LineCollection from an Axes instance? (for example a get_collection method) This would then allow one to 'recycle' existing collections.

Cheers,

Thomas

···

On Mar 29, 2010, at 1:40 PM, Jae-Joon Lee wrote:

As far as I can say, moving around artists from one axes to the other
is NOT recommended. And I encourage you to create separate artists for
each axes rather than try to reuse the existing ones.

For your particular example,

fig = mpl.figure()
ax2 = fig.add_subplot(1,1,1)
for c in ax1.collections:
   c._transOffset=ax2.transData
   ax2.add_collection(c)

should work.

Regards,

-JJ

On Mon, Mar 29, 2010 at 12:24 PM, Thomas Robitaille > <thomas.robitaille@...287...> wrote:

Hello,

In the following example, I am trying to copy over existing collections from one plot to another:

import matplotlib.pyplot as mpl

fig = mpl.figure()
ax1 = fig.add_subplot(1,1,1)
ax1.scatter([0.5],[0.5])
fig.savefig('test1.png')

fig = mpl.figure()
ax2 = fig.add_subplot(1,1,1)
for c in ax1.collections:
   ax2.add_collection(c)
fig.savefig('test2.png')

However, the circle appears in the wrong place in test2.png (close to 0.4, 0.4 instead of 0.5,0.5). Is it not possible/safe to copy over collections in this way? If not, then how should this be done?

Thanks,

Thomas
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Doing this in a general way is quite difficult (if possible) because a
user can set an arbitrary transform for an artist. What we may try to
do is recycling artists whose transform is simple, e.g., transData,
rather than try to come up with a general solution.

I'll see what I can do but I must admit that I'm not very kin to this
kind of feature and it may take a while. I recommend you to open a new
ticket in the feature requests tracker hoping that other developers
or contributors can take a look.

Regards,

-JJ

···

On Mon, Mar 29, 2010 at 1:54 PM, Thomas Robitaille <thomas.robitaille@...287...> wrote:

Hi Jae-Joon,

Thanks for your quick reply! Since for example LineCollections can be created independent of the Axes in which they are going to be plotted through the creation of a LineCollection instance, would it not be possible to have a method that allows one to retrieve an Axes-independent LineCollection from an Axes instance? (for example a get_collection method) This would then allow one to 'recycle' existing collections.

Cheers,

Thomas

On Mar 29, 2010, at 1:40 PM, Jae-Joon Lee wrote:

As far as I can say, moving around artists from one axes to the other
is NOT recommended. And I encourage you to create separate artists for
each axes rather than try to reuse the existing ones.

For your particular example,

fig = mpl.figure()
ax2 = fig.add_subplot(1,1,1)
for c in ax1.collections:
c._transOffset=ax2.transData
ax2.add_collection(c)

should work.

Regards,

-JJ

On Mon, Mar 29, 2010 at 12:24 PM, Thomas Robitaille >> <thomas.robitaille@...287...> wrote:

Hello,

In the following example, I am trying to copy over existing collections from one plot to another:

import matplotlib.pyplot as mpl

fig = mpl.figure()
ax1 = fig.add_subplot(1,1,1)
ax1.scatter([0.5],[0.5])
fig.savefig('test1.png')

fig = mpl.figure()
ax2 = fig.add_subplot(1,1,1)
for c in ax1.collections:
ax2.add_collection(c)
fig.savefig('test2.png')

However, the circle appears in the wrong place in test2.png (close to 0.4, 0.4 instead of 0.5,0.5). Is it not possible/safe to copy over collections in this way? If not, then how should this be done?

Thanks,

Thomas
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Jae-Joon Lee wrote:

Doing this in a general way is quite difficult (if possible) because a
user can set an arbitrary transform for an artist. What we may try to
do is recycling artists whose transform is simple, e.g., transData,
rather than try to come up with a general solution.

Is even that worth the potential extra complexity, both in the code and in the documentation? What is the real benefit?

Eric

···

I'll see what I can do but I must admit that I'm not very kin to this
kind of feature and it may take a while. I recommend you to open a new
ticket in the feature requests tracker hoping that other developers
or contributors can take a look.

http://sourceforge.net/tracker/?atid=560723&group_id=80706&func=browse

Regards,

-JJ

On Mon, Mar 29, 2010 at 1:54 PM, Thomas Robitaille > <thomas.robitaille@...287...> wrote:

Hi Jae-Joon,

Thanks for your quick reply! Since for example LineCollections can be created independent of the Axes in which they are going to be plotted through the creation of a LineCollection instance, would it not be possible to have a method that allows one to retrieve an Axes-independent LineCollection from an Axes instance? (for example a get_collection method) This would then allow one to 'recycle' existing collections.

Cheers,

Thomas

On Mar 29, 2010, at 1:40 PM, Jae-Joon Lee wrote:

As far as I can say, moving around artists from one axes to the other
is NOT recommended. And I encourage you to create separate artists for
each axes rather than try to reuse the existing ones.

For your particular example,

fig = mpl.figure()
ax2 = fig.add_subplot(1,1,1)
for c in ax1.collections:
   c._transOffset=ax2.transData
   ax2.add_collection(c)

should work.

Regards,

-JJ

On Mon, Mar 29, 2010 at 12:24 PM, Thomas Robitaille >>> <thomas.robitaille@...287...> wrote:

Hello,

In the following example, I am trying to copy over existing collections from one plot to another:

import matplotlib.pyplot as mpl

fig = mpl.figure()
ax1 = fig.add_subplot(1,1,1)
ax1.scatter([0.5],[0.5])
fig.savefig('test1.png')

fig = mpl.figure()
ax2 = fig.add_subplot(1,1,1)
for c in ax1.collections:
   ax2.add_collection(c)
fig.savefig('test2.png')

However, the circle appears in the wrong place in test2.png (close to 0.4, 0.4 instead of 0.5,0.5). Is it not possible/safe to copy over collections in this way? If not, then how should this be done?

Thanks,

Thomas
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

I think there are some benefit of moving artists to another axes. Also
this will help enabling moving an axes to another figure.

http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg13544.html

Anyhow, given that I don't know how the implementation will make
things more complicated. I don't think i'm in a good position to
discuss whether it is worth while to do.

While (as I said) I'm not very kin to implementing this feature, I'll
discuss this issue with you and others when I have more idea (or
actual code) in the future.

Regards,

-JJ

···

On Tue, Mar 30, 2010 at 2:56 PM, Eric Firing <efiring@...202...> wrote:

Is even that worth the potential extra complexity, both in the code and in
the documentation? What is the real benefit?