没有合适的资源?快使用搜索试试~ 我知道了~
首页matplotlib命令与格式之tick坐标轴日期格式(设置日期主副刻度)
matplotlib命令与格式之tick坐标轴日期格式(设置日期主副刻度)
5星 · 超过95%的资源 3 下载量 41 浏览量
更新于2023-03-03
评论
收藏 75KB PDF 举报
主要介绍了matplotlib命令与格式之tick坐标轴日期格式(设置日期主副刻度),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
资源详情
资源评论
资源推荐
matplotlib命令与格式之命令与格式之tick坐标轴日期格式坐标轴日期格式(设置日期主副刻度设置日期主副刻度)
主要介绍了matplotlib命令与格式之tick坐标轴日期格式(设置日期主副刻度),文中通过示例代码介绍的非常详细,对
大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
1.横坐标设置时间格式
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
# 配置横坐标为日期格式
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y/%m/%d'))
plt.gca().xaxis.set_major_locator(mdates.DayLocator())
例子:
from datetime import datetime
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
# 生成横纵坐标信息
dates = ['01/02/1991', '01/03/1991', '01/04/1991']
xs = [datetime.strptime(d, '%m/%d/%Y').date() for d in dates]
ys = range(len(xs))
# 配置横坐标
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d/%Y'))
plt.gca().xaxis.set_major_locator(mdates.DayLocator())
# Plot
plt.plot(xs, ys)
plt.gcf().autofmt_xdate() # 自动旋转日期标记
plt.show()
2.设置日期坐标轴主副刻度值
所有坐标轴日期格式类型
MinuteLocator: locate minutes(f)
HourLocator: locate hours
DayLocator: locate specified days of the month
WeekdayLocator: Locate days of the week, e.g., MO, TU
MonthLocator: locate months, e.g., 7 for july
YearLocator: locate years that are multiples of base
RRuleLocator: locate using a matplotlib.dates.rrulewrapper. The rrulewrapper is a simple wrapper around adateutil.rrule (dateutil)
which allow almost arbitrary date tick specifications. See rrule example.
AutoDateLocator: On autoscale, this class picks the best MultipleDateLocator to set the view limits and the tick locations.
(1)获取坐标轴日期格式类型
from matplotlib.dates import DateFormatter, WeekdayLocator, DayLocator, MONDAY,YEARLY
#获取每月一日数据
monthdays = MonthLocator()
#获取每周一的日期数据
mondays = WeekdayLocator(MONDAY)
#获取每日数据
alldays = DayLocator()
# import constants for the days of the week
from matplotlib.dates import MO, TU, WE, TH, FR, SA, SU
# tick on mondays every week
loc = WeekdayLocator(byweekday=MO, tz=tz)
# tick on mondays and saturdays
loc = WeekdayLocator(byweekday=(MO, SA))
# tick on mondays every second week
loc = WeekdayLocator(byweekday=MO, interval=2)
# tick every 5th easter(每隔5个选1个)
rule = rrulewrapper(YEARLY, byeaster=1, interval=5)
loc = RRuleLocator(rule)
(2)设置坐标轴日期格式
#设置主副刻度
ax.xaxis.set_major_locator(mondays)ax.xaxis.set_minor_locator(alldays)
#设置坐标轴刻度标签格式
mondayFormatter = DateFormatter('%Y-%m-%d') # 如:2-29-2015dayFormatter = DateFormatter('%d') # 如:12ax.xaxis.set_major_formatter(mondayFormatter)
#字符串旋转
weixin_38676500
- 粉丝: 9
- 资源: 916
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- RTL8188FU-Linux-v5.7.4.2-36687.20200602.tar(20765).gz
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论10