概述
本文讲解使用plot()画折线图
官方文档:
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html?highlight=plot#matplotlib.pyplot.plot
语法
matplotlib.pyplot.plot(x,y,**kwargs)
参数
- x:类数组,表示x轴上的数据
- y:类数组,表示y轴上的数据
- **kwargs:关键字参数,设置一些属性
- label:添加图例,需要搭配
matplotlib.pyplot.legend()函数使用
参见 https://www.malaoshi.top/show_1EF3nOjya8fx.html - color:设置颜色,如:
color='red',也可以用html中16进制表示颜色,如:color='#ff7733' - linestyle:线样式,默认实线,具体值参见:https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D.set_linestyle
- alpha:透明度,float型
- label:添加图例,需要搭配
例子:绘制一天气温变化图
网址:
http://www.weather.com.cn/weather1d/101060101.shtml#input
import matplotlib.pyplot as plt
temps=[23,22,23,24,27,28,25,23]
hours=list(range(2,26,3))
print(temps)
print(hours)
plt.plot(hours,temps)
# 显示
plt.show()

