【发布时间】:2020-12-17 13:05:03
【问题描述】:
import os
import pandas as pd
import matplotlib.pyplot as plt
import datetime
df = pd.read_excel(DATA_DIR+"/"+file_list[0], index_col="Date")
df.head(5)
smooth = df['Pur. Rate'].rolling(window=20).mean()
smooth.plot()
我得到下图,需要在 x 轴上绘制每个 MONTH-YEAR 的所有日期值。 我想以格式(2 月 19 日)在 x 轴上显示对角格式的所有月份和年份。我可以将绘图的大小放大以适合所有人,因为我会将其保存为 jpg。
我希望 x 轴具有以下值: 1月16日、2月16日、3月16日、4月16日、5月16日、6月16日、7月16日、8月16日、9月16日、10月16日、11月16日、12月16日、1月17日、2月17日…… (我想显示所有这些值,matplotlib 会自动截断这个,我想避免那个)
【问题讨论】:
-
您必须在 matplotlib 中设置正确的定位器和格式化程序才能获得所需的 xticks。请阅读matplotlib tutorial 并询问,如果您仍然无法管理。一般来说,自定义标签涉及两个步骤:locating the ticks and formatting their labels。如果您想更频繁地使用它,您应该熟悉这些概念。
标签: python pandas matplotlib