Skip to content

Feature Requestion: filled step plot #1709

Closed

Description

@jseabold

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

Activity

  1. lebek commented on Mar 30, 2013

    @lebek

    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.

  2. lebek commented on Mar 30, 2013

    @lebek

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

  3. Tillsten commented on Mar 31, 2013

    @Tillsten
    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.)

  4. Tillsten commented on Mar 31, 2013

    @Tillsten
    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.

  5. lebek commented on Apr 1, 2013

    @lebek

    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.

  6. mdboom commented on Apr 1, 2013

    @mdboom
    Member

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

  7. mdboom commented on Apr 1, 2013

    @mdboom
    Member

    @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...

  8. parrenin commented on Aug 16, 2013

    @parrenin

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

  9. added this to the milestone on Aug 17, 2014
  10. tacaswell commented on May 15, 2015

    @tacaswell
    Member

    Closing as duplicate of #643

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions