• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
joyspace
博客园    首页    新随笔    联系   管理    订阅  订阅
python绘制折线图

import datetime
import matplotlib.pyplot as plt
import pylab as mpl
import numpy as np
#数据源
list_date=['20191005','20191014','20191021','20191217',
'20200125','20200331','20200407','20200904',
'20200913','20200927','20201027','20201029',
'20201205','20201207','20201214','20210106',
'20210115','20210214','20210228','20210307',
'20210314','20210406','20210908','20211107']
list_count=[-26.88,-30.07,-17.81,-8.52,-4.32,
-25.83,-30.66,-34.48,-37.69,-28.82,
-12.38,-22.38,-20.20,-6.33,-3.75,
-7.61,-3.57,-10.89,-10.03,-11.66,
-18.71,-19.33,-25.02,-13.14]
mpl.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False
fig=plt.figure(figsize=(8,3))
ax=fig.add_subplot(111)
plt.xlabel('日期')
plt.ylabel('温度/℃')
xs = [datetime.datetime.strptime(d, '%Y%m%d').date() for d in list_date]

#x坐标的刻度值
ar_xticks = np.arange(1, len(list_date)+1, step=1)
plt.xticks(ar_xticks, list_date, rotation=45, fontsize=10)
plt.yticks(np.arange(-36, 0, step=10), fontsize=10)
ax.plot(ar_xticks, list_count, color='r')

 

posted on 2023-01-29 15:48  浪漫的下雨鸟  阅读(87)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3