Correct versions of old commands

Hi everybody,
sorry, I guess the question is trivial, but I confess my matplotlib
and python ignorance.

I'm running some code written by someone else, and apparently some
bits of the code are not compliant with newer versions of matplotlib.
So, how can I rewrite the following, which give AttributError?

self.ax.get_figure().axes =

and

self.ax.get_figure().axes = [self.ax]

Thanks a lot.

Without context, it would be hard to say. What was the exception message? I bet it was a NoneType object being returned by get_figure(), which would mean that the Axes object was created without a figure, which is rarely done.

Also, it looks like the code was trying to manage the hierarchy of objects itself (maybe the code was trying to detach an axes from one figure and transfer to another? Lots of bookkeeping code like this is not needed, but you may still have other issues lurking.

Ben Root

···

On Sunday, September 23, 2012, Giovanni Plantageneto wrote:

Hi everybody,

sorry, I guess the question is trivial, but I confess my matplotlib

and python ignorance.

I’m running some code written by someone else, and apparently some

bits of the code are not compliant with newer versions of matplotlib.

So, how can I rewrite the following, which give AttributError?

self.ax.get_figure().axes =

and

self.ax.get_figure().axes = [self.ax]

Thanks a lot.

One of the suggestions I got works:

Maybe this:

self.ax.get_figure().clf()
self.ax.get_figure().add_axes(self.ax)

But it looks really weird to me.

If I understand it correctly, from matplotlib version 1.1.1 (?)
statements as "self.ax.get_figure().axes = " are not possible any
more as axes are not lists anymore. Don't take my word for it, though.

Thanks for the support.

2012/9/23 Giovanni Plantageneto <g.plantageneto@...287...>:

···

Hi everybody,
sorry, I guess the question is trivial, but I confess my matplotlib
and python ignorance.

I'm running some code written by someone else, and apparently some
bits of the code are not compliant with newer versions of matplotlib.
So, how can I rewrite the following, which give AttributError?

self.ax.get_figure().axes =

and

self.ax.get_figure().axes = [self.ax]

Thanks a lot.

    Hi everybody,
    sorry, I guess the question is trivial, but I confess my matplotlib
    and python ignorance.

    I'm running some code written by someone else, and apparently some
    bits of the code are not compliant with newer versions of matplotlib.
    So, how can I rewrite the following, which give AttributError?

     > self.ax.get_figure().axes =

    and

     > self.ax.get_figure().axes = [self.ax <http://self.ax>]

    Thanks a lot.

Without context, it would be hard to say. What was the exception
message? I bet it was a NoneType object being returned by get_figure(),
which would mean that the Axes object was created without a figure,
which is rarely done.

It looks to me like the code was trying to delete all axes but one from the figure. This probably worked when Figure.axes was a plain list, but for quite some time it has been a read-only list generated from an AxesStack instance.

The code will need rewriting based on an understanding of what it is trying to do, and how mpl works now. There is no shortcut. For this particular problem, you might be able to do something like this:

fig = self.ax.get_figure()
axlist = fig.axes
for ax in axlist:
     if not ax == self.ax:
         fig.delaxes(ax)

Eric

···

On 2012/09/23 9:27 AM, Benjamin Root wrote:

On Sunday, September 23, 2012, Giovanni Plantageneto wrote:

Also, it looks like the code was trying to manage the hierarchy of
objects itself (maybe the code was trying to detach an axes from one
figure and transfer to another? Lots of bookkeeping code like this is
not needed, but you may still have other issues lurking.

Ben Root

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://ad.doubleclick.net/clk;258768047;13503038;j?
AppDynamics Lite | AppDynamics

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

One of the suggestions I got works:

Maybe this:

self.ax.get_figure().clf()
self.ax.get_figure().add_axes(self.ax)

This seems a bit dangerous, because logically, even if does not presently do so, the clf() call could remove the figure reference from self.ax. If you want to go this route, then:

fig = self.ax.get_figure()
fig.clf()
fig.add_axes(self.ax)

Eric

···

On 2012/09/23 9:45 AM, Giovanni Plantageneto wrote:

But it looks really weird to me.

If I understand it correctly, from matplotlib version 1.1.1 (?)
statements as "self.ax.get_figure().axes = " are not possible any
more as axes are not lists anymore. Don't take my word for it, though.

Thanks for the support.

2012/9/23 Giovanni Plantageneto <g.plantageneto@...287...>:

Hi everybody,
sorry, I guess the question is trivial, but I confess my matplotlib
and python ignorance.

I'm running some code written by someone else, and apparently some
bits of the code are not compliant with newer versions of matplotlib.
So, how can I rewrite the following, which give AttributError?

self.ax.get_figure().axes =

and

self.ax.get_figure().axes = [self.ax]

Thanks a lot.

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://ad.doubleclick.net/clk;258768047;13503038;j?
AppDynamics Lite | AppDynamics
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options