Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mpl_toolkits] Allow "figure" kwarg for host functions in parasite_axes #4863

Merged
merged 5 commits into from Nov 5, 2015

Conversation

smheidrich
Copy link
Contributor

Currently, host_axes and host_subplot of mpl_toolkits.axes_grid1 work on pyplot only. This patch allows a kwarg figure (defaulting to pyplot.gcf()) to be passed so it becomes possible to use them on arbitrary figures as well.

@@ -487,7 +487,10 @@ def host_axes(*args, **kwargs):
import matplotlib.pyplot as plt
axes_class = kwargs.pop("axes_class", None)
host_axes_class = host_axes_class_factory(axes_class)
fig = plt.gcf()
if kwargs.get("figure") != None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't do equality comparison to None. Always do is and is not.

@WeatherGod
Copy link
Member

Also needs documentation (although, I am not clear where...). Besides the equality comment, this makes sense to me. Don't know why it wasn't coded that way before...

@smheidrich
Copy link
Contributor Author

@WeatherGod thanks for your correction. Both of these functions weren't documented (except for their usage in examples) to begin with, so I'm not sure either. The whole AxesGrid toolkit seems a bit neglected to me, do people still use it?

@WeatherGod
Copy link
Member

Oh, absolutely it gets used. It is one of the more popular toolkits.

On Tue, Aug 4, 2015 at 5:23 PM, productivememberofsociety666 <
notifications@github.com> wrote:

@WeatherGod https://github.com/WeatherGod thanks for your correction.
Both of these functions weren't documented (except for their usage in
examples) to begin with, so I'm not sure either. The whole AxesGrid toolkit
seems a bit neglected to me, do people still use it?


Reply to this email directly or view it on GitHub
#4863 (comment)
.

@dopplershift
Copy link
Contributor

Someone else just contributed some docs: #4864

@WeatherGod
Copy link
Member

In fact, you might be interested in #4864 (just submitted) where someone gives some love to the documentation.

import matplotlib.pyplot as plt
axes_class = kwargs.pop("axes_class", None)
host_axes_class = host_axes_class_factory(axes_class)
fig = plt.gcf()
if kwargs.get("figure") is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do this as

fig = kwargs.get('figure', None)
if fig is None:
    fig = plt.gcf()

@tacaswell tacaswell added this to the proposed next point release milestone Aug 5, 2015
@tacaswell
Copy link
Member

Sorry this languished, in the future leave a comment after you finish with edits. We don't get notifications on commit pushes, just comments.

tacaswell added a commit that referenced this pull request Nov 5, 2015
…xes_not_pyplot

ENH: Allow "figure" kwarg for host functions in parasite_axes
@tacaswell tacaswell merged commit c594223 into matplotlib:master Nov 5, 2015
@tacaswell
Copy link
Member

This isn't perfect, but does not make it worse.

@FilipDominec
Copy link

Could you, please, point me to a minimum example of using host_axes once

self.fig = matplotlib.figure.Figure(figsize=(8,8))

is defined?

@smheidrich
Copy link
Contributor Author

smheidrich commented Sep 30, 2016

@FilipDominec

hax = host_axes([0.1,0.1,0.8,0.8], figure=fig)
hax.plot([0,1,2,3],[1,2,4,8])
fig.savefig("some_file.png")

Result looks very broken though, even when I set figure=plt.gcf() (which is weird because nothing else happens inside the function when figure is None).

I'm using host_subplot with figure kwarg in my own projects. I think I just added the kwarg for host_axes while I was at it because it was almost identical to host_subplot.

@FilipDominec
Copy link

@smheidrich Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants