1
x1 = [1, 2, 3, 4, 5, 6]
y1 = [6, 5, 4, 3, 2, 1]

fig = plt.figure()
ax = fig.add_subplot(211)
ax.step(x1, y1, alpha=0.8, linewidth=2, color="b", linestyle="--", label="test")

enter image description here

Why the linestyle parameter doesn't effect this plot? And how to make it work? The documentation mentions "Additional keyword args to step() are the same as those for plot()." (doc)

tacaswell
  • 84,579
  • 22
  • 210
  • 199
user2808117
  • 4,497
  • 8
  • 27
  • 36

2 Answers2

1

Add 'dashes=(a,b)' to ax.plot:

import matplotlib.pyplot as plt
x1 = [1, 2, 3, 4, 5, 6]
y1 = [6, 5, 4, 3, 2, 1]

fig = plt.figure()
ax = fig.add_subplot(211)
ax.step(x1, y1, alpha=0.8, linewidth=2, color="b", linestyle="--", dashes=(4,2), label="test")
plt.show()
frits
  • 327
  • 2
  • 15
  • You just pasted the OPs code back with and added import and show which are clearly not the problem. – tacaswell Oct 04 '13 at 14:39
  • The difference is not the import and show but dashes. It works fine with me on python 2.7 with matplotlib 1.1.1. The original code just gives a solid line. Please read next time... – frits Oct 04 '13 at 14:53
  • 1
    You should edit your answer to include an explanation of _what_ is different and why it should work. Please make your answers clear next time. – tacaswell Oct 04 '13 at 15:01
0

What version of matplotlib are you using?

This is a bug/interface issue (PR #1802) that was fixed in 1.3.0.

If you can not upgrade, see the work-around at Linestyle in matplotlib step function.

Community
  • 1
  • 1
tacaswell
  • 84,579
  • 22
  • 210
  • 199