颜色
基础颜色
- b:blue
- g:green
- r:red
- c:cyan 浅蓝绿色
- m:magenta 深粉色
- y:yellow
- k:black
- w:white
其他
- 灰色阴影
color=‘数值’ - html 十六进制
利用颜色代码工具
color=‘#FF ’ - RGB元组
color=(,,)
代码
color
import numpy as np
import matplotlib.pyplot as plt
y=np.arange(1,5)
plt.plot(y,color='green')
plt.plot(y+1,color='0.5')
plt.plot(y+2,color='#FF00FF')
plt.plot(y+3,color=(0.1,0.2,0.3))
plt.show()
样式
点型
- . point
- , pixel
- o circle
- v triangle_down
- ^ triangle_up
- < triangle_left
- ‘>’ triangle_right
- 1 tri_down
- 2 tri_up
- 3 tri_left
- 4 tri_right
- S octagon
- s square
- ‘*’ star
- h hexagon1
- H hexagon2
- '+ ’ plus
- x x
- D diamond
- d thin_diamond
- | yline
- _ hline
线型
- 实线 -
- 虚线 –
- 点划线 -.
- 点线 :
样式字符串
把颜色、点型、线型写成一个字符串
例:cx–
代码
marker 默认画出线段
无marker 默认画出点
画多条线自动会改变颜色
import numpy as np
import matplotlib.pyplot as plt
y=np.arange(1,5)
plt.plot(y,marker='o')
plt.plot(y+1,'D')
plt.plot(y+2,marker='^')
plt.plot(y+3,'p')
plt.show()
import numpy as np
import matplotlib.pyplot as plt
y=np.arange(1,5)
plt.plot(y,'--')
plt.plot(y+1,'-.')
plt.plot(y+2,'-')
plt.plot(y+3,':')
plt.show()
import numpy as np
import matplotlib.pyplot as plt
y=np.arange(1,5)
plt.plot(y,'cx--')
plt.plot(y+1,'gp:')
plt.plot(y+2,'bp-')
plt.show()