Skip to content
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

Feature Requestion: filled step plot #1709

Closed
jseabold opened this issue Jan 26, 2013 · 9 comments
Closed

Feature Requestion: filled step plot #1709

jseabold opened this issue Jan 26, 2013 · 9 comments
Milestone

Comments

@jseabold
Copy link
Contributor

This was asked a long time ago, and I just ran into a similar need. It would be nice to be able to easily make a filled step plot. The solutions I've come up with are suboptimal.

http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg13072.html

@lebek
Copy link

lebek commented Mar 30, 2013

This sounds like a bug to me, as Eric says in the mailing list:

The Line2D object should not be modifying the
coordinates it is given. At the very least, its get_path() should
return the actual path it is drawing; at present it does not.

@lebek
Copy link

lebek commented Mar 30, 2013

Also see #643, especially the fix proposed by @ycopin.

@Tillsten
Copy link
Contributor

I tried to solve this issue, but there some small refactoring in Lines2D is necessary:
self._path is set by recache(). The path drawn for step-lines is only calculated when drawing.
The easiest solution seems to be to move the calculation from "real" path to recache.
Because i am not sure about side effects, i need some input from more experienced
developers? @efiring @mdboom @dmcdougall

Also while studying the code, i found the following lines:

    transformed_path = self._get_transformed_path()
    path, affine = transformed_path.get_transformed_path_and_affine()
    path = affine.transform_path(path)

Are the last two lines not redundant? (But i don't know matplotlib interals good enough to be sure.)

@Tillsten
Copy link
Contributor

A easier solution would be to just add a get_drawn_path method, which returns "real" path (and if necessary calculates it). The step-calculation function would be shared with the draw methods.

@lebek
Copy link

lebek commented Apr 1, 2013

We fixed this as part of a group assignment on my CS course. We did a bit of refactoring in Line2D and made get_ydata and get_xdata return the actual drawn data (when orig=False). Filled step plots are then as easy as:

lines = plt.step(x, y)
plt.fill_between(lines[0].get_xdata(orig=False), 0, lines[0].get_ydata(orig=False))
plt.show()

To make things more convenient we added a fill kwarg to plt.plot and plt.step:

plt.step(x, y, fill='red')
plt.show()

Not sure if either change would be desirable upstream but I'll try to put together a PR.

@mdboom
Copy link
Member

mdboom commented Apr 1, 2013

@Tillsten: Those lines are not redundant. The first performs the non-affine part of the transform, the second performs the affine part.

@mdboom
Copy link
Member

mdboom commented Apr 1, 2013

@Tillsten: I'm not sure what the side effects you're suggesting would be -- it probably depends on what ways users are relying on the way it works now -- but maybe as a start we could do that refactor and run it against the test suite...

@parrenin
Copy link

An additionnal request is to have an equivalent of 'fill_between' for step.

@tacaswell tacaswell added this to the v1.5.x milestone Aug 17, 2014
@tacaswell
Copy link
Member

Closing as duplicate of #643

tacaswell added a commit to tacaswell/matplotlib that referenced this issue May 15, 2015
Add ability to fill between 'step' plots.

Closes matplotlib#643 and matplotlib#1709
tacaswell added a commit to tacaswell/matplotlib that referenced this issue May 15, 2015
Add ability to fill between 'step' plots.

Closes matplotlib#643 and matplotlib#1709
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Jul 16, 2015
Add ability to fill between 'step' plots.

Closes matplotlib#643 and matplotlib#1709
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Jul 16, 2015
Add ability to fill between 'step' plots.

Closes matplotlib#643 and matplotlib#1709
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants