Matplotlib,用日期作为横坐标
2017-03-18 22:25
447 查看
Code Example:
Result:
Ref
http://stackoverflow.com/questions/9627686/plotting-dates-on-the-x-axis-with-pythons-matplotlib
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()
Result:
Ref
http://stackoverflow.com/questions/9627686/plotting-dates-on-the-x-axis-with-pythons-matplotlib
相关文章推荐
- matplotlib命令与格式:tick坐标轴日期格式(设置日期主副刻度)
- matplotlib命令与格式:坐标轴数值格式(日期格式,百分比,科学记数)
- Python第三方库——Matplotlib_子图共享坐标轴
- Python利用matplotlib做图中图及次坐标轴
- python中利用matplotlib.patches在一个坐标轴上添加画的图形
- matplotlib的基本用法(二)——设置坐标轴
- matplotlib的基本用法(六)——设置坐标轴label
- matplotlib命令与格式:tick坐标轴主副刻度设置
- Python 使用matplotlib画图添加标注、及移动坐标轴位置
- matplotlib模块数据可视化-修改坐标轴位置
- matplotlib 纵坐标轴显示数据值
- Python实现在matplotlib中两个坐标轴之间画一条直线光标的方法
- python matplotlib坐标轴设置的方法
- matplotlib坐标轴刻度-【老鱼学matplotlib】
- 【Matplotlib】线设置,坐标显示范围
- matplotlib 可视化 —— 移动坐标轴(中心位置)
- Python 使用matplotlib画图添加标注、及移动坐标轴位置
- matplotlib时间坐标设置
- 对python中Matplotlib的坐标轴的坐标区间的设定实例讲解
- matplotlib去掉坐标轴刻度