8000 Deprecate allowing scalars for fill_between where by timhoffm · Pull Request #14511 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Deprecate allowing scalars for fill_between where #14511

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

Conversation

timhoffm
Copy link
Member
@timhoffm timhoffm commented Jun 9, 2019

PR Summary

When working on #14510, I realized that fill_between(..., where=...) accepts scalars and broadcasts them. This is against the documentation, which requires data with the same size as x (https://matplotlib.org/devdocs/api/_as_gen/matplotlib.axes.Axes.fill_between.html).

In particular the following caught me by surprise:

x = [0, 1, 2, 3]
y1 = [1, 1, 0, 0]
y2 = [0, 0, 1, 1]
plt.plot(x, y1, 'o--')
plt.plot(x, y2, 'o--')
plt.fill_between(x, y1, y2, where=y1 > y2, alpha=0.3)

image

I would have expected that only the left part is filled. That would indeed have happened if y1, y2 were numpy arrays, but the comparison of lists y1 > y2 results in a single bool that is accepted by fill_between.

Because of this chance of mis-use I propose to deprecate the behavior and not just change the docs.

Copy link
Contributor
@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

I'm usually in favor of broadcasting whenever possible, but here I guess one can just not pass the where kwarg at all if one wants True everywhere (and for False everywhere, why are you even using fill_between?); plus x, y1 and y2 don't broadcast against each other, so heh.

Please also make the same change for fill_betweenx.

@timhoffm timhoffm force-pushed the deprecate-fill_between-where_scalar branch from 5b84ed4 to 5345cb6 Compare July 22, 2019 18:55
@timhoffm
Copy link
Member Author

added fill_betweenx

@tacaswell tacaswell merged commit 965540c into matplotlib:master Aug 8, 2019
@timhoffm timhoffm deleted the deprecate-fill_between-where_scalar branch August 8, 2019 19:19
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
0