当前位置:   article > 正文

Python matplotlib画气温变化的折线图_python在多个坐标系绘制沈阳和广州4月份温度变化折线图

python在多个坐标系绘制沈阳和广州4月份温度变化折线图
from matplotlib import pyplot as plt
fig = plt.figure(figsize=(20,8),dpi=80)
#宽20,高8,dpi表示清晰程度
x = range(0,26,2)
y = [15,13,14.5,17,20,25,26,26,27,22,18,15,13]
plt.plot(x,y)
#绘图
plt.xticks(range(0,25,1))
#设置x轴刻度
plt.savefig("./sig_size.png")
plt.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

效果
在这里插入图片描述
2.

from matplotlib import pyplot as plt
import random
#matplotlib下显示中文的方法
plt.rcParams['font.sans-serif'] = ['KaiTi'] # 指定默认字体
plt.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题
x = range(0,120)
y = [random.randint(20,25)for i in range(120)]
fig = plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y)
_xtick_labels = ["10点{}分".format(i) for i in range(60)]
_xtick_labels += ["11点{}分".format(i) for i in range(60)]
plt.xticks(list(x)[::3],_xtick_labels[::3],rotation=45)
#添加描述信息
plt.xlabel("时间")
plt.ylabel("温度 单位(℃)")
plt.title("10点到12点每分钟的气温变化情况")
plt.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

效果
在这里插入图片描述

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号