当前位置:   article > 正文

matplotlib中散点图的简单使用及美化_mr散点图美化

mr散点图美化
气温随时间变化的规律

为寻找当地气温随时间变化的规律,对四十天内气温的变化进行统计得到如下数组
[32, 25, 15, 19, 18, 23, 27, 23, 24, 24, 24, 25, 17, 17, 17, 22, 26, 27, 28, 28, 20, 17, 19, 19, 23, 19, 19, 23, 24, 26, 27, 28, 28, 29, 26, 27, 29, 30, 29, 29]

from matplotlib import pyplot as plt
import matplotlib
matplotlib.rc("font",family='FangSong')

temperature_1 = [32, 25, 15, 19, 18, 23, 27, 23, 24, 24, 24, 25, 17, 17, 17, 22, 26, 27, 28, 28, 20, 17, 19, 19, 23, 19, 19, 23, 24, 26, 27, 28, 28, 29, 26, 27, 29, 30, 29, 29]
temperature_2 = [24, 17, 15, 20, 18, 21, 23, 23, 23, 23, 24, 22, 17, 18, 17, 20, 24, 27, 29, 28, 17, 17, 21, 22, 25, 21, 20, 23, 25, 23, 27, 29, 29, 28, 24, 26, 29, 30, 27, 25]
count = 0
for i in temperature_1:
    count +=1

x = range(1,count+1,1)
y_1 = temperature_1
y_2 = temperature_2

_xticks_labels = ["第{}日".format(i) for i in x]
plt.xticks(x[::3], _xticks_labels[::3], rotation=45)

plt.grid(alpha=0.3)
plt.scatter(x, y_1, label="临汾")
plt.scatter(x, y_2, label="太原")
plt.legend()

plt.xlabel("时间", loc="right")
plt.ylabel("温度(单位:摄氏度)", loc="top")
plt.title("四十日两地气温变化散点图")
plt.subplots_adjust(left=0.1, right=0.97, top=0.95, bottom=0.15) 

plt.savefig("./scatter.png")

plt.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 绘制命令为plt.scatter()
  • plt.subplots_adjust(left=0.1, right=0.97, top=0.95, bottom=0.15) :
    • 根据需要对图片内容与边缘的距离进行调整,数值范围为0~1;
    • 距离参数以左边框与下边框为基准;

该代码运行结果为:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/181869?site
推荐阅读
相关标签
  

闽ICP备14008679号