Skip to content

Consolidate agg-buffer examples. #11726

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 1 commit into from
Jul 26, 2018
Merged

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jul 21, 2018

agg_oo_sgskip, webapp_demo_sgskip, and histogram_demo_canvasagg_sgskip
were all demonstrating the same thing (how to create a Figure outside of
pyplot, attach a canvas, and get the data out either saved to a file or
as a string. Consolidate them into a single example, with the minimal
amount of plotting. (PIL.Image.frombytes exists since Pillow 2.0 which
is the first version to support Py3.)

agg_buffer is very similar but uses another (worse?) technique to attach
an agg buffer; make data extraction simpler but otherwise keep it
separate for now.

Other related examples include:

  • agg_buffer_to_array which directly does
    np.asarray(canvas.renderer._renderer), which is on the one side bad
    as it uses a private API, but on the other hand the only way (AFAIK)
    to access the underlying buffer without copy[*];
  • print_stdout_sgskip, which does use pyplot to set up the agg buffer.

Let's defer the discussion for these two examples to later.

[*] The poorly named buffer_rgba method actually does a copy (in PyBytes_FromStringAndSize). Note that the Py2 version used to return a Py2 buffer object, with no copy (https://github.com/matplotlib/matplotlib/blob/v2.2.2/src/_backend_agg_wrapper.cpp#L589). This (the buffer protocol) is also already implemented by the renderer object itself; it's just a matter of publically exposing it.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

agg_oo_sgskip, webapp_demo_sgskip, and histogram_demo_canvasagg_sgskip
were all demonstrating the same thing (how to create a Figure outside of
pyplot, attach a canvas, and get the data out either saved to a file or
as a string.  Consolidate them into a single example, with the minimal
amount of plotting.  (PIL.Image.frombytes exists since Pillow 2.0 which
is the first version to support Py3.)

agg_buffer is very similar but uses another (worse?) technique to attach
an agg buffer; make data extraction simpler but otherwise keep it
separate for now.

Other related examples include:
- agg_buffer_to_array which directly does
  `np.asarray(canvas.renderer._renderer)`, which is on the one side bad
  as it uses a private API, but on the other hand the only way (AFAIK)
  to access the underlying buffer without copy;
- print_stdout_sgskip, which does use pyplot to set up the agg buffer.

Let's defer the discussion for these two examples to later.
@anntzer anntzer force-pushed the canvasagg-examples branch from 1d02261 to 870f851 Compare July 21, 2018 17:14
@ImportanceOfBeingErnest
Copy link
Member

At least agg_oo_sgskip is always been a standard example for people to link to from outside. Now the link adress has changed as it moved to /misc/, but at least the title did stay the same, so it's possible to find. If that example now vanishes, those links get completely broken. Is it necessary to completely remove it? I guess there is no way to do a http redirection for examples, right?


I know that canvas.renderer._renderer fails for some backends, at least for PyCharm's InterAgg. A bulletproof alternative would sure be desireable.

@anntzer
Copy link
Contributor Author

anntzer commented Jul 21, 2018

I don't mind moving everything to agg_oo_buffer instead if that makes you more comfortable.

@ImportanceOfBeingErnest
Copy link
Member

Ok, thinking about it, those links are broken anyways, so one needs to locate the examples through search anyways. The new name and title are much better now, so this is probably the more sustainable solution.
So what about mentioning the old names of the examples in the text, such that search finds them, something like

Note that this examples contains the content of the former agg_oo_sgskip, webapp_demo_sgskip, and histogram_demo_canvasagg_sgskip examples.

possibly in smaller font (if there exists a spinx rule for that).

@anntzer
Copy link
Contributor Author

anntzer commented Jul 21, 2018

The link to agg_oo_sgkip won't be broken if I move everything to it...

@ImportanceOfBeingErnest
Copy link
Member

It is already broken. Versions of that example:

meaning that if it's moved again now, the link will be as broken as if you didn't do anything to it, because I strongly doubt that new links to the devdocs (devdocs/gallery/misc/agg_oo_sgskip.html) are already beeing created somewhere.

@anntzer
Copy link
Contributor Author

anntzer commented Jul 21, 2018

Let's just leave this as it is then? I know that @tacaswell has thought about examples redirection but I'd rather have a general solution before starting to pepper docs with refs to no-longer-existing docs.

@ImportanceOfBeingErnest
Copy link
Member

Ok, someone decided to break that link prior to this. So assuming there was a reason for this and since it got approved, this PR just builds on top and is fine by itself.

@jklymak jklymak merged commit 0887e2a into matplotlib:master Jul 26, 2018
@anntzer anntzer deleted the canvasagg-examples branch July 26, 2018 22:01
@QuLogic QuLogic modified the milestones: v3.1, v3.0 Jul 26, 2018
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.

5 participants