pandas.DataFrame.plot()更新后不显示x轴

时间:2018-09-19 15:24:13

标签: python pandas matplotlib

import pandas as pd
import numpy as np

import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use('seaborn-white')

燃尽数据帧:

                Forecast    Actual
Baseline        11422       11422
February 2018   11422       11325
March 2018      11420       10717
April 2018      11415       10272
May 2018        11393       8771
June 2018       11382       7750
July 2018       10069       6940
August 2018     6330        6038
September 2018  6153        4998

用于通过调用以下命令生成具有x轴的图表:

burndown_data.plot(figsize=(15,3),grid=True,title=title,marker='o')

enter image description here

,但是升级到最新的熊猫后,x轴丢失。该如何解决?

enter image description here

当我尝试这种方法时:

Matplotlib:: Not Showing all x-axis data frame variable

我有一个错误: enter image description here

1 个答案:

答案 0 :(得分:2)

您正在将数据帧索引(burndown_data.index)作为plt.xticks()的第一个参数传递。根据{{​​3}},第一个参数应为:

  

应放置刻度的位置列表。您可以传递一个空列表来禁用xticks。

所以我会按照以下方式做些事情:

import pandas as pd
import matplotlib.pyplot as plt

index = ['Baseline','February 2018','March 2018','April 2018','May 2018','June 2018','July 2018','August 2018','September 2018']

burndown_data = pd.DataFrame([[11422,       11422],
    [11422,       11325],
    [11420,       10717],
    [11415,       10272],
    [11393,       8771],
    [11382,       7750],
    [10069,       6940],
    [6330,        6038],
    [6153,        4998]],
    columns=['Forecast','Actual'], index=index)

plt.style.use('seaborn-white')
burndown_data.plot(figsize=(15,3),grid=True,title='Your Plot',marker='o')
plt.xticks(list(range(len(index))), burndown_data.index, fontsize=12)
plt.show()

产生以下内容:

docs