Use Agg for rendering in the Mac OSX backend #6178

Merged
merged 6 commits into from Mar 28, 2016

Conversation

Projects
None yet
8 participants
Owner

mdboom commented Mar 17, 2016

I got tired of the bug reports about this one, so thought I'd start seeing how hard this would be. Turns out, not very hard.

Based on @mdehoon's desire to deprecate the macosx backend, one option we've thrown about in order to not regress in terms of features, and not require extra dependencies is to pare down the existing macosx backend so all the rendering happens in the Agg backend. This fixes many of the rendering differences, both visual and performance-wise, between the macosx and the *Agg backends.

I've tested on El Cap, and it seems to work just fine in terms of speed. Retina displays are fully supported -- it should work to move a window from a Retina to non-Retina display, but I don't have such a setup to test on.

Cc: @jenshnielsen and @efiring for extra Mac testing -- esp. if you are on earlier versions than El Capitain. If using anaconda, don't forget to run with pythonw.

@mdboom mdboom Use Agg for rendering in the Mac OSX backend
eea4d80

mdboom added this to the 2.1 (next point release) milestone Mar 17, 2016

mdboom added the needs_review label Mar 17, 2016

Contributor

matthew-brett commented Mar 17, 2016

Nice!

Will this make any difference to the requirement for a Python framework build by any chance? It's a significant pain point.

Owner

mdboom commented Mar 18, 2016

Unfortunately, this makes no difference with respect to a framework build. Anaconda has a nice workaround to make a build that "works both ways" (it's not really a framework build, but it has a .app wrapper). I think overtime other distros will probably adopt a similar approach.

Owner

efiring commented Mar 18, 2016

Wow! Works on a Retina with Mavericks! Sharp and snappy!
Will this also make it possible to add restore_region() and copy_from_bbox to the canvas, so that animations (e.g. double_pendulum_animated) and widgets (e.g. lasso_selector_demo) will work?

Owner

mdboom commented Mar 18, 2016

Yes -- I was just reminded that restore_region() doesn't work on macosx backend. It should be pretty straightforward to add that now.

Member

WeatherGod commented Mar 18, 2016

Except wasn't there fundamental conflicts in the design of the macosx
backend that prevented this? I remember very detailed explanations on the
differences between macosx and gtk/qt drawing models as the basis for that
conflict.

On Fri, Mar 18, 2016 at 7:12 AM, Michael Droettboom <
notifications@github.com> wrote:

Yes -- I was just reminded that restore_region() doesn't work on macosx
backend. It should be pretty straightforward to add that now.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#6178 (comment)

@jenshnielsen jenshnielsen commented on an outdated diff Mar 18, 2016

lib/matplotlib/backends/backend_macosx.py
_macosx.FigureCanvas.__init__(self, width, height)
+ @property
+ def renderer(self):
@jenshnielsen

jenshnielsen Mar 18, 2016

Owner

tight_layout looks for get_renderer https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/tight_layout.py#L218 I guess we should either change it or implement get_renderer on top of the property

Owner

jenshnielsen commented Mar 18, 2016

Seems to work really great

Contributor

mdehoon commented Mar 19, 2016

@efiring I think restore_region and copy_from_bbox will work with agg. With the native implementation, restore_region and copy_from_bbox needed to be done from inside the callback function during the event loop to satisfy Apple's API requirements. As agg has its own image buffer, restore_region and copy_from_bbox can now be done independently of the event loop.

@mdboom mdboom Make animation work in OSX backend
142d9fc
Owner

mdboom commented Mar 21, 2016

Animations now work. It's a bit less efficient than it could be -- the blitting to the Agg buffer is for specific rectangles of the image, but the blitting of the figure to the window is always still the entire figure. That could probably be made to work, but I'm not sure how much benefit it would really have -- the real benefit of the animation code is to not draw (vectorize) more than we have to. Blitting is pretty cheap relative to those things.

Contributor

matthew-brett commented Mar 21, 2016

My animation code works at good speed with this PR - thanks very much for doing this.

@mdboom mdboom Simplify
cf435b8

mdboom added some commits Mar 21, 2016

@mdboom mdboom Remove Numpy dependency
cb57075
@mdboom mdboom Remove unnecessary bitmap writing code
742d698
Owner

efiring commented Mar 21, 2016

There is still a problem with lasso_selector_demo.py. The curve is drawn displaced from the cursor by a large fraction of the window size, and everything seems to being getting selected.

Owner

mdboom commented Mar 21, 2016

There is still a problem with lasso_selector_demo.py. The curve is drawn displaced from the cursor by a large fraction of the window size, and everything seems to being getting selected.

It looks like mouse events aren't being properly scaled by the device scale.

@mdboom mdboom Fix scaling of mouse events
79be27d
Owner

mdboom commented Mar 22, 2016

I'm of two minds on where this should be milestoned as well. It certainly makes it easier to have consistent look-and-feel across the major backends, which is what 2.0 is "about". But I can see it either way.

Contributor

matthew-brett commented Mar 22, 2016

It would be great to have this in for 2.0 - it looks like it will make the OSX backend easier to use, and less puzzling to people reading examples and documentation for other backends.

Owner

efiring commented Mar 22, 2016

Given all of the bugs that this addresses, an argument can be made for putting it in 1.5.x! And given how long it is taking us to get 2.0 out, I think that waiting even longer, for 2.1, would be a mistake.
Some more comprehensive testing is still needed, most likely, in case there are still problems like the one you just fixed; but after that, the sooner it can get in, the sooner we can all breath a sigh of relief.

Member

QuLogic commented Mar 26, 2016

Considering how large #5718 was, and it still got into 2.x, I don't see a problem including this PR too.

@efiring efiring merged commit b4bed49 into matplotlib:master Mar 28, 2016

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

efiring removed the needs_review label Mar 28, 2016

Owner

efiring commented Mar 28, 2016

@mdboom I tried to cherry-pick this to v2.x, but failed--would you take care of that, please?

QuLogic added the GUI/osx label Mar 28, 2016

@mdboom mdboom added a commit that referenced this pull request Mar 29, 2016

@efiring @mdboom efiring + mdboom Merge pull request #6178 from mdboom/macagg
Use Agg for rendering in the Mac OSX backend
e981e1e
Owner

mdboom commented Mar 29, 2016

Cherry-picked to 2.x as e981e1e

Hi, apologies for asking a 'rookie' question over here. I recently migrated from linux to a retina mac and found the macosx backend to be very slow at rendering stuff. other backends either don't work or display very low resolution graphics. if I understood correctly this is part of the issue that was fixed here.
I have cloned the matplotlib repository and installed it as indicated in the readme, but once I try to import the peplos module it complains about python not being installed as a 'framework'.
I understand that this has to do with virtual environments, but nothing more; I have an Anaconda installation and tried calling 'pythonw -m qtconsole' but with no success. It does however work fine from ipython (jupyter), albeit still being slow in displaying the graphics.

If anyone could give me a suggestion of how to make the qtconsole import matplotlib fine I would greatly appreciate it, thanks!

@bearstrong bearstrong added a commit to bearstrong/matplotlib that referenced this pull request Apr 1, 2016

@efiring @bearstrong efiring + bearstrong Merge pull request #6178 from mdboom/macagg
Use Agg for rendering in the Mac OSX backend
e21eec2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment