Skip to content

plot_surface docstring + edge case fix #9277

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
Oct 5, 2017

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Oct 4, 2017

PR Summary

Update doctrings of plot_surface & plot_wireframe.

Emphasize the downsampling. Clarify when the defaults for rstride and
cstride apply.

Allow passing infinite rcount & ccount to plot_surface, plot_wireframe.

Passing an infinite rcount and ccount is the easiest way to ensure the
data does not get downsampled (which I still think is a misfeature, but
that's a battle for another day), but would result in a stride of zero;
instead, ensure that the stride is at least 1.

Closes #8706.

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

@anntzer anntzer changed the title Plot surface plot_surface docstring + edge case fix Oct 4, 2017
'''
The *rcount* and *ccount* kwargs, which both default to 50,
determine the maximum number of samples used in each direction. If
the input data is larger, it will be downsampled to these numbers
Copy link
Member

Choose a reason for hiding this comment

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

might be worth saying 'downsampled by slicing' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

... I would have thought it was downsampled by averaging (well, perhaps not).
This behavior is seriously ridiculous. Anyways, fixed the doc accordingly.

@tacaswell tacaswell added this to the 2.1.1 (next bug fix release) milestone Oct 4, 2017
along this direction, producing a 3D line plot rather than a
wireframe plot.
Added in v2.0.0.
.. warning::
Copy link
Member

Choose a reason for hiding this comment

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

Why are you making this a warning?

@WeatherGod
Copy link
Member

"""
(which I still think is a misfeature, but
that's a battle for another day)
"""
The downsampling is not a misfeature, so please, do not treat it as such in the documentation. Instead, emphasize the fact that one could pass infinity to avoid any automated downsampling.

This is the default sampling method unless using the 'classic'
style. Will raise ValueError if both stride and count are
specified.
Added in v2.0.0.
Copy link
Member

Choose a reason for hiding this comment

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

The fact that this kwarg was added in v2.0.0 is important. I can't tell you the number of times I run into situations where I tried using a feature in an older codebase only to discover that the feature isn't available in the older version of the package because it wasn't documented as such on the website.

sample the input data to generate the graph. If 1k by 1k
arrays are passed in, the default values for the strides will
result in a 100x100 grid being plotted. Defaults to 10.
Raises a ValueError if both stride and count kwargs
Copy link
Member

Choose a reason for hiding this comment

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

You are also lost the information that the stride and count kwargs can't be used together, and will raise a ValueError.

@anntzer
Copy link
Contributor Author

anntzer commented Oct 4, 2017

I'm not particularly interested in relitigating #3142, but the main point is that (regardless of whether it is a good design, and as reported in #8706) it is rathe unintuitive that a function defaults to silently discarding some of the input data (well, the only other example I can think of in mpl is #8278, where I took the same side of the discussion), and this kind of behavior should be emphasized in the docs.

The fact that the count and stride arguments are mutually exclusive with each other is, well, documented in the parameter list next to rstride, cstride (I don't think mentioning the exception class is particularly relevant here, if you are so careful that you want to wrap the thing in a try... except you may as well not pass count and stride at the same time.

grepping for versionadded/versionchanged in the codebase shows that it is exclusively used in mplot3d (+ 1 example, + 1 docstring of a function I backported from numpy). And even there, basically no change has been logged between 1.2 and 2.0 (rcount/ccount where added in 2.0, then voxels in 2.1), which suggests that there is probably a lot of missing version information anyways. Let's just stop pretending we're keeping that information available and up to date.

@jklymak
Copy link
Member

jklymak commented Oct 4, 2017

I was mystified by this default behaviour once upon a time as well. It is indeed obvious that matplotlib is doing something to the data. On the other hand, its not at all clear that it is by design and that there are arguments to set the decimation, called cstride and rstride no less, which are terms I wasn't familiar with before running into this behaviour. If you aren't going to change the defaults, any documentation that highlights this behaviour in a stark way is most welcome IMHO.

@WeatherGod
Copy link
Member

I am not saying that it shouldn't be highlighted. I am against putting it in as a warning. If anything, make it a note. As for mutual exclusivity, I missed it in your diff, so I take that back.

As for the versionadded thing, we aren't pretending anything. I have been meticulous in my maintenance of the versionadded info in mplot3d. There haven't been many new features added since I did my overhaul 5 or so years ago. Please don't remove useful information.

@anntzer
Copy link
Contributor Author

anntzer commented Oct 4, 2017

I think the new version is a reasonable middle ground for everyone.

Copy link
Member

@WeatherGod WeatherGod left a comment

Choose a reason for hiding this comment

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

Agreed, this is a definite improvement for the docstring. Just noticed a possible typo, though.

rstride, cstride : int
Downsampling stride in each direction. These arguments are
mutually exclusive with *rcount* and *ccount*. If only one of
*rcount* or *ccount* is set, the other defaults to 10.
Copy link
Member

Choose a reason for hiding this comment

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

Whoops, I think you mean If only one of *rstride* or *cstride* here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, fixed (below too)

rstride, cstride : int
Downsampling stride in each direction. These arguments are
mutually exclusive with *rcount* and *ccount*. If only one of
*rcount* or *ccount* is set, the other defaults to 1. Setting a
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

…me}.

Docstrings: Emphasize the downsampling.  Clarify when the defaults for
rstride and cstride apply.

Passing an infinite rcount and ccount is the easiest way to ensure the
data does not get downsampled (which I still think is a misfeature, but
that's a battle for another day), but would result in a stride of zero;
instead, ensure that the stride is at least 1.
@WeatherGod WeatherGod merged commit 9cb0f74 into matplotlib:master Oct 5, 2017
@anntzer anntzer deleted the plot-surface branch October 5, 2017 02:07
@tacaswell
Copy link
Member

@meeseeksdev backport to v2.1.x

dstansby added a commit that referenced this pull request Oct 7, 2017
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.

4 participants