Python/matplotlib绘图模板
绘图一般有几部分是常用的操作项,将其归类建立模板,再绘图时直接通过模板绘图,打开或者关闭相应的开关即可完成修改
代码
import matplotlib
.pyplot
as plt
import numpy
as np
x
= np
.linspace
(0,5,200)
y1
= np
.sin
(2*np
.pi
*x
)
y2
= np
.cos
(2*np
.pi
*x
)
plt
.figure
()
ax
= plt
.axes
()
ax
.spines
['top'].set_visible
(False)
ax
.spines
['right'].set_visible
(False)
plt
.grid
(axis
="both",linestyle
='-.',c
='b')
plt
.plot
(x
,y1
,'c--')
plt
.plot
(x
,y2
,'r-.')
plt
.text
(1,0.5,"text")
plt
.legend
(["y1","y2"])
plt
.xlabel
("xlabel")
plt
.ylabel
("ylabel")
plt
.title
("title")
plt
.show
()
图
更多Python数据科学相关见专题Python数据科学技能索引