I'm trying to code pyplot
plot that allows different marker styles. The plots are generated in a loop. The markers are picked from a list.
For demonstration purposes I also included a colour list.
The versions are Python 2.7.9
, IPython 3.0.0
, matplotlib 1.4.3.
Here's a simple code example:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
x=np.arange(0,10)
y=x**2
markers=['d','-d','-']
colors=['red', 'green', 'blue']
for i in range(len(markers)):
plt.plot(x, y, marker=markers[i], color=colors[i])
plt.show()
This manages to produce only the plot for marker='d', for the marker '-d'
it returns the error:
...
C:\Users\batman\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\markers.pyc in set_marker(self, marker)
245 self._marker_function = self._set_vertices
246 except ValueError:
--> 247 raise ValueError('Unrecognized marker style {}'.format(marker))
248
249 self._marker = marker
ValueError: Unrecognized marker style -d
But, I can get it to work by writing plt.plot(x, y, markers[i], color=colors[i])
instead.
The color=...
in comparison works.
I assume it has something to do with the the special characters.
I tried other markers:
The markers .
,*
work.
The markers :
,--
don't.
I tried prefixing the marker string with r
or u
(with # -*- coding: utf-8 -*-
). Didn't help.
Do I have to escape the marker strings or what's wrong here?