先來看看我們要實現的效果圖吧:
先來看看Matplotlib的plot函數原型
plt.plot(x, y, color='r', maker='o', linestyle='-', linewidth=2.0)
注意上面的color、maker、linestyle在同時畫多組線的時候,我們想調線性、顏色的時候,你估計會想到用個列表的形式實現:
maker=['o', '^', '*']
可惜,plot函數並沒有實現這個功能,只能一次次指定,這里可以借助python的itertools迭代實現,還是以我上面的圖作為例子,看看是怎么實現的吧。
make = itertools.cycle(["o","*","^"]) for i in [2013, 2014, 2015]: axf.plot(axe.get_xticks(), right_data[i], linestyle='-', marker=make.next(), linewidth=2.0)
注意:參考4實現這個方法使用zip,以后可以注意下。
#參考#
- http://matplotlib.org/users/pyplot_tutorial.html#controlling-line-properties
- http://stackoverflow.com/questions/29163096/matplotlib-different-dashed-lines-instead-of-coloured-lines
- http://stackoverflow.com/questions/23000578/cycling-through-list-of-linestyles-when-plotting-columns-of-a-matrix-in-matplotl
- http://stackoverflow.com/questions/33523476/matplotlib-plot-columns-of-pandas-dataframe-with-different-marker-and-label