matplotlib 绘制折现图

# -*- 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()


在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值