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

Skip to content

drawstyle with "step" has display error #16635

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

Closed
mankoff opened this issue Mar 2, 2020 · 2 comments
Closed

drawstyle with "step" has display error #16635

mankoff opened this issue Mar 2, 2020 · 2 comments
Labels
Community support Users in need of help.

Comments

@mankoff
Copy link

mankoff commented Mar 2, 2020

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.

@ImportanceOfBeingErnest
Copy link
Member

That's definitely not a display error. That is, the step demo shows what we would expect.

I can see how adding an extra line-segment at the beginning or end might be useful in some applications, however, we do in general not know how long that line should be. Consider e.g. x = [1.1, 1.7, 2.1]; y = [0,1,2]; what would in that case the expected output look like?

@timhoffm
Copy link
Member

timhoffm commented Mar 2, 2020

@mankoff Thanks for the report. Unfortunately, steps is not designed to what you‘ve described in your expectation. As indicated, it‘s also not trivial, to generalize this to non-uniform distances.

This has been discussed extensively in #15019, #15065 and the links therein. You are welcome to join the discussion in the latter. I‘m going to close this to keep this topic in one place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community support Users in need of help.
Projects
None yet
Development

No branches or pull requests

4 participants