码迷,mamicode.com
首页 > 其他好文 > 详细

Pandas 时间序列数据绘制X轴主要刻度和次要刻度

时间:2015-12-15 11:54:18      阅读:5099      评论:0      收藏:0      [点我收藏+]

标签:

先上效果图吧(图中Tue表示周二):

技术分享

Pandas和matplotlib.dates都是使用matplotlib.units来定位刻度。

matplotlib.dates可以方便的手动设置刻度,同时pandas似乎可以自动调整格式。

直接上代码吧:

 

# -*- coding: utf-8 -*-
"""
Created on Tue Dec 15 10:43:01 2015

@author: vgis
"""

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt 
import matplotlib.dates as dates

idx = pd.date_range(2011-05-01, 2011-07-01)
s = pd.Series(np.random.randn(len(idx)), index=idx)

fig, ax = plt.subplots()
ax.plot_date(idx.to_pydatetime(), s, v-)
ax.xaxis.set_minor_locator(dates.WeekdayLocator(byweekday=(1),
                                                interval=1))
ax.xaxis.set_minor_formatter(dates.DateFormatter(%d\n%a))
ax.xaxis.grid(True, which="minor")
ax.yaxis.grid()
ax.xaxis.set_major_locator(dates.MonthLocator())
ax.xaxis.set_major_formatter(dates.DateFormatter(\n\n\n%b\n%Y))
plt.tight_layout()
plt.show()

 

 

 

#参考#

 

Pandas 时间序列数据绘制X轴主要刻度和次要刻度

标签:

原文地址:http://www.cnblogs.com/nju2014/p/5047490.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!