Skip to content

WIP/ENH: pyplot internals #906

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

Merged
merged 5 commits into from
Nov 19, 2013
Merged

Conversation

dengemann
Copy link
Member

In part addresses #903
probably more examples need to be updated.
This also addresses the matplotlib issues with Anaconda (should now work without self compiled matplotlib) reported in #728 by @kambysese.
We're now able to understand the reasons and extract two insigths:

  1. don't mix plt.axes with plt.subplots
  2. axes.figure | axes.get_figure and plt.gcf() are not the same. Really make sure get the right figure when doing multi-axis plots where multiple calls of ave.plot are made to draw on the same figure.

In addition many inconveniences can be avoided by explicitly invoking %pylab inline in a notebook.
This should be added to the docs.

You can checkout this notebook for exploring:

http://nbviewer.ipython.org/7533330

The multi-axis figures now work in the notebook.
The block thing still needs a fix.

@dengemann
Copy link
Member Author

Invoking %pylab inline resolves our block issue.
I think we're good.
The last thing missing is going through all examples and removing plt.figure calls to avoid empty figures popping up.

@agramfort
Copy link
Member

travis is not happy:

File "/home/travis/virtualenv/python2.7_with_system_site_packages/lib/python2.7/site-packages/mne-0.7.git-py2.7.egg/mne/viz.py", line 1241, in plot_evoked
fig.show()
AttributeError: 'Figure' object has no attribute 'show'

@dengemann
Copy link
Member Author

This shows us that we don't control whether pyplot is really used. The pyplot figure hase a show method, the pylab hasn't ...

@dengemann
Copy link
Member Author

Here's a helpful discussion of the problem. Will look into it tonight.
matplotlib/matplotlib#835

@dengemann
Copy link
Member Author

@agramfort WDYT about my last commit.

if show:
plt.show()
if show and plt.get_backend() != 'agg':
fig.show()
Copy link
Member

Choose a reason for hiding this comment

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

how about if

hasattr(fig, 'show')

?

would that work?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's almost equivalent ...
The reasons leading to fig objects without show method are backend-related. E.g. 'Agg' as used in tests will produce such objects while plt.show calls would just pass and do nothing.
The variant I proposed would allow us to learn about additional backends / constellations where this fails ...
But I'm fine with going for attribute checking.

agramfort added a commit that referenced this pull request Nov 19, 2013
@agramfort agramfort merged commit 4d734a6 into mne-tools:master Nov 19, 2013
@agramfort
Copy link
Member

Point taken

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.

2 participants