Skip to content

drawstyle with "step" has display error #16635

Description

@mankoff

Bug report

Bug summary

When plotting with drawstyle='steps' (or steps-pre, steps-mid, or steps-post) there is a graphic display error. This was submitted to Pandas (pandas-dev/pandas#31965) but I realize it may be a Matplotlib issue.

Specifically, on the graphic below and when using these two vectors:

x = [0,1,2]
y = [0,1,2]
  • steps-pre and steps imply that the y values is 1 in x=[0,1]. I would argue that the proper way to interpret this data is that y = 0 at x = 0, and presumably remains at 0 until the y value is updated to 1 at x=1. These two options essentially drop the first data point. There is some indication of an (x,y) = (0,0), but it is minimal.
  • steps-post has the same issue but at the end.
  • steps-mid graphically weights the values unevenly. The y=1 value has twice the weight of the other two line segments, based on length.
  • The fifth panel is graphically correct in my opinion, but requires a modification of the data before plotting it.

Code for reproduction

import matplotlib.pyplot as plt

x = [0,1,2]
y = [0,1,2]

fig = plt.figure(1, figsize=(3,7))

ax = fig.add_subplot(611)
ax.plot(x,y, drawstyle='steps-pre')
ax.set_ylabel('steps-pre')

ax = fig.add_subplot(612)
ax.plot(x,y, drawstyle='steps')
ax.set_ylabel('steps')

ax = fig.add_subplot(613)
ax.plot(x,y, drawstyle='steps-mid')
ax.set_ylabel('steps-mid')

ax = fig.add_subplot(614)
ax.plot(x,y, drawstyle='steps-post')
ax.set_ylabel('steps-post')

x.append(x[-1]+1)
y.append(y[-1])

ax = fig.add_subplot(615)
ax.plot(x,y, drawstyle='steps-post')
ax.set_ylabel('steps-post\nw/ extra data')

Actual outcome

steps-post

Expected outcome

See bottom panel.

The plot should display y[0] from x[0] to x[1], y[n] from x[n] to x[n+1], and therefore needs to have an x[n+1] appended to the end of the plot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions