Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linestyle in matplotlib step function

Tags:

Is it possible to set the linestyle in a matplotlib step function to dashed, dotted, etc.?

I've tried:

step(x, linestyle='--'),  step(x, '--') 

But it did not help.

like image 916
user2061207 Avatar asked Mar 03 '13 16:03

user2061207


People also ask

What is Linestyle?

A line style identifies a particular line of text in the report file that contains information to be extracted. Each line style must be defined such that Extract Editor can identify the same line throughout the report file.

What is PLT CLF () in Python?

matplotlib.pyplot.clf() Function. The clf() function in pyplot module of matplotlib library is used to clear the current figure.

What does PLT axis (' equal ') do?

The plt. axis() method allows you to set the x and y limits with a single call, by passing a list which specifies [xmin, xmax, ymin, ymax] : In [11]: plt.


1 Answers

As of mpl 1.3.0 this is fixed upstream


You have to come at it a bit sideways as step seems to ignore linestyle. If you look at what step is doing underneath, it is just a thin wrapper for plot.

You can do what you want by talking to plot directly:

import matplotlib.pyplot as plt  plt.plot(range(5), range(5), linestyle='--', drawstyle='steps') plt.plot(range(5), range(5)[::-1], linestyle=':', drawstyle='steps') plt.xlim([-1, 5]) plt.ylim([-1, 5]) 

example

['steps', 'steps-pre', 'steps-mid', 'steps-post'] are the valid values for drawstyle and control where the step is drawn.

Pull request resulting from this question, I personally think this is a bug. [edit: this has been pulled into master and should show up in v1.3.0].

like image 149
tacaswell Avatar answered Sep 21 '22 13:09

tacaswell