<p>首先我们需要选择随机标记。可以通过包含所有可用标记的<code>matplotlib.markers.MarkerStyle.markers</code>字典来完成。另外,markers意味着“nothing”,以“tick”和“caret”开头的标记应该再删除一些<a href="http://matplotlib.org/api/markers_api.html" rel="nofollow noreferrer">information</a>关于标记。让我们用有效的标记列出列表,然后从中随机选择绘制数据帧所需的数量,或者您可以使用第二个选项与<code>filled_markers</code>:</p>
<pre><code>import matplotlib as mpl
import numpy as np
# create valid markers from mpl.markers
valid_markers = ([item[0] for item in mpl.markers.MarkerStyle.markers.items() if
item[1] is not 'nothing' and not item[1].startswith('tick')
and not item[1].startswith('caret')])
# use fillable markers
# valid_markers = mpl.markers.MarkerStyle.filled_markers
markers = np.random.choice(valid_markers, df.shape[1], replace=False)
</code></pre>
<p>例如:</p>
^{pr2}$
<p>然后对于标记,您可以绘制数据帧,并通过<code>set_marker</code>方法为每一行设置标记。然后您可以在绘图中添加图例:</p>
<pre><code>import pandas as pd
np.random.seed(2016)
df = pd.DataFrame(np.random.rand(10, 8))
ax = df.plot(kind='line')
for i, line in enumerate(ax.get_lines()):
line.set_marker(markers[i])
# for adding legend
ax.legend(ax.get_lines(), df.columns, loc='best')
</code></pre>
<p>原件:</p>
<p><a href="https://i.stack.imgur.com/sP8Sj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sP8Sj.png" alt="enter image description here"/></a></p>
<p>修改日期:</p>
<p><a href="https://i.stack.imgur.com/qyA96.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qyA96.png" alt="enter image description here"/></a></p>