Python处理时间日期坐标轴过程详解
作者:微岩 发布时间:2021-04-28 08:05:27
标签:python,处理,坐标轴
1. 前言
当日期数据作为图表的坐标轴时通常需要特殊处理,应为日期字符串比较长,容易产生重叠现象
2. 设定主/次刻度
2.1 引用库
from matplotlib.dates import DateFormatter, WeekdayLocator, DayLocator, MONDAY,YEARLY
2.2 获取每月/周/日数据
获取每月一日数据
monthdays = MonthLocator()
获取每周一的日期数据
mondays = WeekdayLocator(MONDAY) # 主要刻度
获取每日数据
alldays = DayLocator() # 次要刻度
2.3 设定主/次刻度
ax.xaxis.set_major_locator(mondays)
ax.xaxis.set_minor_locator(alldays)
2.4 设定格式
mondayFormatter = DateFormatter('%Y-%m-%d') # 如:2-29-2015
dayFormatter = DateFormatter('%d') # 如:12
ax.xaxis.set_major_formatter(mondayFormatter)
3. 字符串旋转
for label in ax1.get_xticklabels():
label.set_rotation(30)
label.set_horizontalalignment('right')
4. 效果
来源:https://blog.csdn.net/matrix_laboratory/article/details/50699786
0
投稿
猜你喜欢
- 通过PyFetion可以很方便的使用python来用飞信发送短信,下面贴出代码:from fetion import *import osd
- 1、首先访问http://www.python.org/download/去下载最新的python版本。2、安装下载包,一路next。3、为
- 本文实例为大家分享了微信小程序实现简单倒计时的具体代码,供大家参考,具体内容如下任务描述:计时器任务要求:案例描述:设计一个实现倒计时功能的
- 本文实例为大家分享了Python之给我一面国旗的具体代码,供大家参考,具体内容如下1、“给我一面国旗@微信官方”今天“给我一面国旗@微信官方
- 前言上一篇文章Go 实现 WebSockets和什么是 WebSockets我们先介绍了什么是 WebSock
- 前言前面一直使用命令行运行pytest用例,本篇来学下使用pytest.main()来运行测试用例pytest.main()args 传一个
- GO语言结构体方法跟结构体指针方法的区别首先,我定了三个接口、一个结构和三个方法:type DeptModeA interface {Nam
- 在实际工作中,有些场景下,因为产品既有功能限制,不支持特大文件的直接处理,需要把大文件进行切割处理。当然可以通过UltraEdit编辑工具,
- 日期是许多 JavaScript 应用程序的基本组成部分,无论是在网页上显示当前日期还是处理用户输入以安排事件。但以清晰一致的格式显示日期对
- 1、在JavaScript中,arguments对象是比较特别的一个对象,实际上是当前函数的一个内置属性。arguments非常类似Arra
- 当需要实现html页面部分模块截图并具有保存图片功能时,前台直接生成截图并下载会方便的多。多的不说,直接看代码首先我们需要引入2个js文件:
- 背景在我的 《Vue 3 开发企业级音乐 App》课程问答区,有个同学提了个问题,在歌手列表到歌手详情页面到转场动画中,只有进入动画,却没有
- 0x00 起因接触网安快一年了,爱收集一些字典啊敏感目录文件啊什么的。收集多了难免有重复,并且有的也需要合并使用方便。自己就写了一个小小的脚
- 目录项目地址运行环境运行方法数据爬取(jd.comment.py)模型训练(train.py)情感分析(sentiment.analysis
- 最近在使用爬虫爬取数据时,经常会返回403代码,大致意思是该IP访问过于频繁,被限制访问。限制IP访问网站最常用的反爬手段了,其实破解也很容
- 这篇文章主要介绍了Python定义函数时参数有默认值问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需
- 并发是一个很酷的话题,一旦你掌握了它,就会成为一笔巨大的财富。说实话,我一开始很害怕写这篇文章,因为我自己直到最近才对并发性不太适应。我已经
- 什么是迭代器迭代是 python 中访问集合元素的一种非常强大的一种方式。迭代器是一个可以记住遍历位置的对象,因此不会像列表那样一次性全部生
- 目录一、前言二、操作 MongoDB1、安装 pymongo2、连接 MongoDB3、选择数据库4、选择集合5、插入数据6、查询
- 我就废话不多说了,直接上代码吧!import paramikoimport pymysqlimport timelinux = ['