# -*- coding: utf-8 -*-
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import random
# 保证生成的图片在浏览器内显示
#%matplotlib inline
# 保证能正常显示中文(Mac)
#plt.rcParams['font.family'] = ['Arial Unicode MS']
# 模拟海南一天的温度变化
# 生成x轴的24小时
hainan_x = [h for h in range(0, 24)]
# 生成y轴的温度随机值(15, 25)
hainan_y = [random.randint(15, 25) for t in range(0, 24)]
# 设置画板属性
plt.figure(figsize = (12, 6), dpi = 100)
# 往画板绘图
plt.plot(hainan_x, hainan_y, label="海南")
## 生成24小时的描述
x_ = [x_ for x_ in range(0, 24)]
x_desc = ["{}时".format(x_desc) for x_desc in x_]
#
## 设置x轴显示 24小时
plt.xticks(x_, x_desc)
#
## 生成0至30度的描述
#y_ = [y_ for y_ in range(0, 30)][::2]
#y_desc = ["{}℃".format(y_desc) for y_desc in y_]
# 设置y轴显示温度描述
#plt.yticks(y_, y_desc)
# 指定x y轴的名称
plt.xlabel("时间")
plt.ylabel("温度")
# 指定标题
plt.title("一天内温度的变化")
# 显示图例
plt.legend(loc="best")
# 将数据生成图片, 保存到当前目录下
plt.savefig("./t.png")
# 在浏览器内展示图片
plt.show()
matplotlib 绘制折现图
最新推荐文章于 2022-02-24 10:45:44 发布