-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Better object-oriented interface for users #1457
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
Conversation
I'll give it a try as soon as I finish setting up my workspace. But I'll review your changes tomorrow. |
@@ -327,9 +326,17 @@ def __init__(self, | |||
self.set_tight_layout(tight_layout) | |||
|
|||
self._axstack = AxesStack() # track all figure axes and current axes | |||
self._axobservers = [] | |||
self.canvas = self._setup_canvas() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the original problem with your first PR was that, if a user wants to setup a figure using a backend that isn't the one in rcParams['backend']
they will have instantiated two different canvases:
For example, suppose my rcParams['backend']
was TkAgg
and I wanted to create a PDF canvas for my figure, I would have to create the figure instance (which creates a TkAgg canvas instance) before I can tell it to use my own PDFCanvas instance.
I don't use the OO interface all too much (pyplot is fine for me - I use the helpers it gives me and I don't rely on the state machine too much), so I might be completely off the mark with these comments. Please tell me so in no uncertain terms 😉 .
Cheers,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pelson I don't think that's right. I think the original issue was that I assumed the construction of the canvas was a standard interface. This was not the case for TkAgg
, requiring an extra kwarg. In the original PR, I set up the canvas corresponding to the value in rcParams['backend']
. The following snippet might help:
import matplotlib
matplotlib.use('gtkagg') # this sets rcParams['backend'] = 'gtkagg'
from matplotlib.figure import Figure # set up the canvas defined by the backend above
I do exactly the same here, but now I'm using the manager
to bypass a lot of the variation in backend set-up that pyplot
makes so opaque.
@dmcdougall so even though 1462 got linked with this PR, it was really just a reminder for you to update |
On Friday, November 9, 2012, Paul Ivanov wrote:
Yes, that's exactly right.
Damon McDougall |
@dmcdougall I think we can move ahead with this. It looks like a change to the docstring of Figure.show() is also needed. What else, besides a rebase? |
I'll need to update the Testing this is hard. The real test will be to get people using it and seeing if it breaks anything. I will update this tomorrow. I presume the reason this doesn't merge cleanly is because of the recent PEP8 changes to the figure module. |
Essentially what this is doing is taking a part of what was originally "pylab support"--the FigureManager, pylab_setup, and _pylab_helpers--and using it reduce the need to import pyplot. |
On Tue, Feb 19, 2013 at 1:18 AM, Eric Firing notifications@github.com wrote:
I see. Thanks for investigating. I think my original intention was I'd be happy to document the lack of GUI backend support, but perhaps
and
Damon McDougall |
Your opening description of this PR is all about gui backends, but in fact I think that the method will only work for non-gui backends. |
I agree. Thanks for your time. |
A second attempt at addressing #1094. My initial attempt was a combination of #1125 and #1201. This went embarrassingly wrong, broke lots of things and was consequently reverted in #1221.
Here's example usage:
I have tried it with Qt4, GTK and OS X backends and it seems to work. I'd like other people to test it out, though. Obviously this PR is not complete, the
update
method needs to raise exceptions in the appropriate places (non-GUI backends).Good or bad, feedback is welcome and appreciated.