Skip to content

Use Agg for rendering in the Mac OSX backend #6178

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 6 commits into from
Mar 28, 2016
Merged

Conversation

mdboom
Copy link
Member

@mdboom 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 added this to the 2.1 (next point release) milestone Mar 17, 2016
@matthew-brett
Copy link
Contributor

Nice!

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

@mdboom
Copy link
Member Author

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.

@efiring
Copy link
Member

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?

@mdboom
Copy link
Member Author

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.

@WeatherGod
Copy link
Member

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)

_macosx.FigureCanvas.__init__(self, width, height)

@property
def renderer(self):
Copy link
Member

Choose a reason for hiding this comment

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

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

@jenshnielsen
Copy link
Member

Seems to work really great

@mdehoon
Copy link
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
Copy link
Member Author

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.

@matthew-brett
Copy link
Contributor

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

@efiring
Copy link
Member

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.

@mdboom
Copy link
Member Author

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
Copy link
Member Author

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.

@matthew-brett
Copy link
Contributor

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.

@efiring
Copy link
Member

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.

@QuLogic
Copy link
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
@efiring
Copy link
Member

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 QuLogic modified the milestones: 2.0 (style change major release), 2.1 (next point release) Mar 28, 2016
mdboom pushed a commit that referenced this pull request Mar 29, 2016
Use Agg for rendering in the Mac OSX backend
@mdboom
Copy link
Member Author

mdboom commented Mar 29, 2016

Cherry-picked to 2.x as e981e1e

@ezatterin
Copy link

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 pushed a commit to bearstrong/matplotlib that referenced this pull request Apr 1, 2016
Use Agg for rendering in the Mac OSX backend
@anntzer anntzer mentioned this pull request Jul 17, 2018
2 tasks
lpsinger added a commit to lpsinger/matplotlib that referenced this pull request Dec 22, 2024
According to
https://matplotlib.org/stable/users/explain/figure/figure_intro.html#saving-figures:

> Many types of output are supported, including raster formats like
> PNG, GIF, JPEG, TIFF and vector formats like PDF, EPS, and SVG.

However, GIF support was broken by matplotlib#6178. Restore GIF support.
QuLogic pushed a commit that referenced this pull request Jan 16, 2025
* DOC / BUG: Fix savefig to GIF format with .gif suffix

According to
https://matplotlib.org/stable/users/explain/figure/figure_intro.html#saving-figures:

> Many types of output are supported, including raster formats like
> PNG, GIF, JPEG, TIFF and vector formats like PDF, EPS, and SVG.

However, GIF support was broken by #6178. Restore GIF support.

* Update lib/matplotlib/backends/backend_agg.py

Co-authored-by: Thomas A Caswell <tcaswell@gmail.com>

* Update lib/matplotlib/testing/decorators.py

---------

Co-authored-by: Thomas A Caswell <tcaswell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants