Python繪圖之——matplotlib顏色與線條

參考網址:
http://stackoverflow.com/questions/22408237/named-colors-in-matplotlib
http://stackoverflow.com/questions/8409095/matplotlib-set-markers-for-individual-points-on-a-line

  1. 常用顏色:
    八種內建默認顏色縮寫
    b: blue
  g: green
  r: red
  c: cyan
  m: magenta
  y: yellow
  k: black
  w: white

其他顏色表示方法:灰色陰影,html 十六進制RGB 元組

  1. 簡單例子:繪製y=x2 曲線
import matplotlib.pyplot as plt   
plt.subplots(1, 1)
x= range(100)
y= [i**2 for i in x]
plt.plot(x, y, linewidth = '1', label = "test", color='y', linestyle=':', marker='|')
plt.legend(loc='upper left')
plt.show()

結果:

3. 第二個參考網址給出的linestyle可選參數:

'-'       solid line style
'--'      dashed line style
'-.'      dash-dot line style
':'       dotted line style

4.第二個參考網址給出的marker可選參數:

'.'       point marker
','       pixel marker
'o'       circle marker
'v'       triangle_down marker
'^'       triangle_up marker
'<'       triangle_left marker
'>'       triangle_right marker
'1'       tri_down marker
'2'       tri_up marker
'3'       tri_left marker
'4'       tri_right marker
's'       square marker
'p'       pentagon marker
'*'       star marker
'h'       hexagon1 marker
'H'       hexagon2 marker
'+'       plus marker
'x'       x marker
'D'       diamond marker
'd'       thin_diamond marker
'|'       vline marker
'_'       hline marker

4.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章