I'm writing a script that will do some plotting. I want it to plot several data series, each with its unique line style (not color). I can easily iterate through a list, but is there such a list already available in python?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
In python3 the
.keys()
method returns adict_keys
object and not alist
. You need to pass the results tolist()
to be able to index the array as you could in python2. e.g. this SO questionSo to create iterable arrays for lines, colors and markers you can use something like.
According to the doc you could find them by doing this :
You can do the same with markers
EDIT: In the latest versions, there are still the same styles, but you can vary the space between dots/lines.
From my experience it is nice to have the colors and markers in a list so I can iterate through them when plotting.
Here's how I obtain the list of such things. It took some digging.
You can copy the dictionary from the Linestyle example:
You can then iterate over the linestyles
Or you just take a single linestyle out of those,
I'm not directly answering the question of accessing a list, but it's useful to have one more alternative on this page: there is an additional way to generate dashed line styles.
You can generate lines between A and B with transversal stripes like
by increasing the width of your line and specifying a custom dash pattern:
ax.plot(x, y, dashes=[30, 5, 10, 5])
The documentation for
matplotlib.lines.Line2D
says this aboutset_dashes(seq)
:I think it could have been said better: as it paints the line, the sequence of numbers specifies how many points are painted along the line, then how many points are left out (in case there are two numbers), how many are painted, how many are unpainted (in case of four numbers in the sequence). With four numbers, you can generate a dash‒dotted line: [30, 5, 3, 5] gives a 30-point-long dash, a 5-point gap, a 3-point dash (a dot), and a 5-point gap. Then it repeats.
This page of the documentation explains this possibility. Look here for two different ways of doing it.
plot
documentationhttp://matplotlib.org/1.5.3/api/pyplot_api.html#matplotlib.pyplot.plot has a list of line + marker styles:
Since this is part of the
pyplot.plot
docstring, you can also see it from the terminal with: