Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH : stepfill between #4433

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 9 commits into from
Jul 22, 2015
Merged

Conversation

tacaswell
Copy link
Member

import matplotlib.pyplot as plt
import numpy as np

x = y = np.arange(5)

fig, ax_list = plt. subplots(3, 1)
for ax, where in zip(ax_list, ['pre', 'post', 'mid']):
    ax.step(x, y, where=where, color='r', zorder=5, lw=5)
    ax.step(x, -y, where=where, color='k', zorder=5, lw=5)
    ax.fill_between(x, y, -y, step_where=where, where=[1, 1 ,0, 1, 1])


fig, ax_list = plt. subplots(3, 1)
for ax, where in zip(ax_list, ['pre', 'post', 'mid']):
    ax.step(x, y, where=where, color='r', zorder=5, lw=5)
    ax.step(x, -y, where=where, color='k', zorder=5, lw=5)
    ax.fill_between(x, y, -y, step_where=where)



fig, ax_list = plt. subplots(3, 1)
for ax, where in zip(ax_list, ['pre', 'post', 'mid']):
    ax.step(x, y, where=where, color='r', zorder=5, lw=5)
    ax.fill_between(x, y, 0, step_where=where)

Generates:

so2

so3

so1

The interaction with where is a bit strange, but I think it is defendable as correct.

This stils needs tests + docs for the new feature.

@tacaswell tacaswell added this to the next point release milestone May 15, 2015
@tacaswell tacaswell changed the title Enh stepfill between ENH : stepfill between May 15, 2015
@tacaswell
Copy link
Member Author

@efiring @mdboom Comments on this? I would like to get feed back on the handling of mid + where before I write tests (which will probably just be the above examples).

@efiring
Copy link
Member

efiring commented May 19, 2015

Yes, the "where" kwarg is confusing and surprising. First, I would expect "where" to be used in a way that matches its use in step. Second, your example of a "where" kwarg has the surprising result that a single zero knocks out two blocks of fill; presumably this means there is no way to knock out a single block. Maybe "where" could replace "step_where", and then a "skip" could replace "where"; "skip" would be like a mask (True is masked, so skip the point). Then the "mid" case is easy--there is one color block per point. For "pre" and "post" probably the simplest thing would be to require and use only n-1 values, corresponding to the filled blocks.

Are masked arrays also supported?

@efiring
Copy link
Member

efiring commented May 19, 2015

How about kwarg "step" for "mid, pre, post", and "skip" as described above?

@tacaswell
Copy link
Member Author

where has been in the API as long as I remember and knocking out two squares is consistent with the current fill_between behaviour.

import matplotlib.pyplot as plt
import numpy as np

x = y = np.arange(5)

fig, ax_list = plt. subplots(3, 1)

for ax, where in zip(ax_list, ['pre', 'post', 'mid']):
    ax.step(x, y, where=where, color='r', zorder=5, lw=5)
    ax.step(x, -y, where=where, color='k', zorder=5, lw=5)
    ax.fill_between(x, y, -y, where=[1, 1 ,0, 1, 1])

so

I suspect that ma works (I was thinking about that when I wrote it), but have not tested.

@efiring
Copy link
Member

efiring commented May 19, 2015

OK, we are stuck with "where", which is like the inverse of the mask if the y values were a masked array. Nevertheless, I'm not sure that keeping full consistency with the non-step behavior is a good idea. What will people actually want to do? Will people want to be able to knock out a single block? I've never used "where", so I don't have use cases in mind. I'm not necessarily opposed to your consistency argument--just trying to anticipate complaints.

As for "step_where": having the "where" in that kwarg name makes it unnecessarily confusing, given that there is a plain "where" kwarg as well. Is there any reason not to just call it "step", or use "linestyle" or "style"?

@tacaswell
Copy link
Member Author

I am sold on changing step_where -> step. I will try to get to that
tonight.

I think the use-case for fill_between is skewed towards large numbers of
points ex ax.fill_between(x, y1, y2, where=y2 > .5) with len(x) >>100 in
which case taking out two bins is not a huge deal.

On Tue, May 19, 2015 at 1:08 PM Eric Firing [email protected]
wrote:

OK, we are stuck with "where", which is like the inverse of the mask if
the y values were a masked array. Nevertheless, I'm not sure that keeping
full consistency with the non-step behavior is a good idea. What will
people actually want to do? Will people want to be able to knock out a
single block? I've never used "where", so I don't have use cases in mind.
I'm not necessarily opposed to your consistency argument--just trying to
anticipate complaints.

As for "step_where": having the "where" in that kwarg name makes it
unnecessarily confusing, given that there is a plain "where" kwarg as well.
Is there any reason not to just call it "step", or use "linestyle" or
"style"?


Reply to this email directly or view it on GitHub
#4433 (comment)
.

@WeatherGod
Copy link
Member

This just needs a whats new entry before this gets merged, right?

@tacaswell
Copy link
Member Author

Added what's new and example.

This also has some of my ideas on how to deal with labeled data and how to start fixing hist in general.

Changes to docstring to attempt to conform to numpydoc
format.
Added 3 public functions for converting points -> steps for the 3 step
locations + 1 private function for input validation
Use the centralized version of the points -> step conversion.

Slightly questioning my API choices on the cbook functions due to
awkwardly large number of .T to make this work here.
Add dict to cbook to map strings -> functions
Add ability to fill between 'step' plots.

Closes matplotlib#643 and matplotlib#1709
@tacaswell tacaswell force-pushed the enh_stepfill_between branch from 0562b46 to e89238b Compare July 16, 2015 04:10
@tacaswell
Copy link
Member Author

rebased to deal with conflicts in .travis.yaml

@@ -0,0 +1,12 @@
Add step kwmargs to fill_between
Copy link
Member

Choose a reason for hiding this comment

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

sp: kwargs

right edge of the last bin.

values : array
A length n array of bin
Copy link
Member

Choose a reason for hiding this comment

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

"bin" -> "bin counts or values" (?)

@efiring
Copy link
Member

efiring commented Jul 17, 2015

Apart from the docstring tweaks, I think this is ready to go, right?

@tacaswell
Copy link
Member Author

Yes, I'll take care of that now (I wrote some fo those examples at stupid oclock in the morning due to my sleep schedule being very messed up after scipy, I am surprised any of it is in English)

@tacaswell
Copy link
Member Author

closes #643

@tacaswell
Copy link
Member Author

The test failure is from the doc build timing out which has been fixed on master, can this be merged?

efiring added a commit that referenced this pull request Jul 22, 2015
@efiring efiring merged commit a892633 into matplotlib:master Jul 22, 2015
@tacaswell tacaswell deleted the enh_stepfill_between branch July 22, 2015 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants