python画图把时间作为横坐标的方法

yipeiwu_com5年前Python基础

1、需要将时间字符串转换成datetime类型,语法:data[‘time'] = pd.to_datetime(data[‘time'])

2、将时间列设置成索引列data.set_index(‘time')

3、画图分两种

(1) matplotlib.pyplot方式

打印某一列数据,直接data[‘some_columns'].plot(),会自动将时间作为横坐标

(2) pycharts方式

from pyecharts import Bar
bar = Bar("数据分析")

labels = data.columns.tolist()
for la in labels:
  # print("标签:",la,"时间:", hebing4[[la]].index,"数据:", hebing4[[la]].values)
  bar.add(la, data[la].index, data[la].values, is_stack=True, mark_point=["max", "min"],
  is_datazoom_show=True, # 默认为 X 轴,横向
  datazoom_type="slider",
  datazoom_range=[10, 25],
  # 新增额外的 dataZoom 控制条,纵向
  is_datazoom_extra_show=True,
  datazoom_extra_type="slider",
  datazoom_extra_range=[10, 25],
  is_toolbox_show=False,)
bar.render(r"/home/result/packetlen_avg.html")

以上这篇python画图把时间作为横坐标的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

pygame游戏之旅 计算游戏中躲过的障碍数量

pygame游戏之旅 计算游戏中躲过的障碍数量

本文为大家分享了pygame游戏之旅的第8篇,供大家参考,具体内容如下 定义一个计数函数: def things_dodged(count): font = pygame.font...

Python的Django框架中消息通知的计数器实现教程

故事的开始:.count() 假设你有一个Notification Model类,保存的主要是所有的站内通知: class Notification(models.Model):...

Python重新引入被覆盖的自带function

幸运的是, 这一问题还是很容易解决的, 我们只需要使用__builtins__: from __builtins__ import int as py_int 这样一来我们又可以...

Python iter()函数用法实例分析

本文实例讲述了Python iter()函数用法。分享给大家供大家参考,具体如下: python中的迭代器用起来非常灵巧,不仅可以迭代序列,也可以迭代表现出序列行为的对象,例如字典的键、...

详解Python学习之安装pandas

详解Python学习之安装pandas

一、python pip的安装与使用 1、pip 是 Python 包管理工具,该工具提供了对Python 包的查找、下载、安装、卸载的功能。 目前如果你在 python.or...