本文总结使用python绘制折线图,使用的函数为matplotlib.pyplot模块。
方法很简单,首先定义两个列表,一个列表作为x轴数值,一个列表作为y轴数值。使用plot函数即可以绘制曲线图。
import matplotlib.pyplot as plt
class ZheXianPlot(object):
def __init__(self):
self.run()
def run(self):
plt.figure(figsize=(8,4))
x=['6点','7点','8点','9点','10点','11点','12点','13点','14点','15点','16点','17点','18点']
y=[50,70,100,70,40,30,50,40,60,40,30,80,90]
plt.plot(x,y,linewidth=3,linestyle='dashed',marker='s',markersize=10)
plt.rcParams['font.sans-serif']=['Microsoft YaHei'] #设置字体为微软雅黑体,保证正常显示中文
plt.rcParams['axes.unicode_minus']=False
plt.show()
if __name__=="__main__":
ZheXianPlot()
生成的图片样式如下: