Pandas xlabel does not show values

前端 未结 2 1466
旧巷少年郎
旧巷少年郎 2021-01-28 04:38

I have a pandas dataframe

jul.head()

which contains

However, when I try to plot my data, I can\'t figure out how to show my i

2条回答
  •  深忆病人
    2021-01-28 05:21

    This should work fine in pandas 0.20. For some reason newer versions of pandas kill the ticklabels.

    import matplotlib.pyplot as plt
    import pandas as pd
    
    df = pd.DataFrame({"value" : [0.1, 0.3, 0.2]}, index=list("ABC"))
    
    ax = df.plot(y='value', label='july')
    ax.set_xlabel("pandas "+pd.__version__, fontsize=12)
    
    plt.show()
    

    v 0.20.1

    v 0.23.1

    You can set the ticklabels yourself in pandas 0.23

    ax.set_xticks(range(len(df.index)))
    ax.set_xticklabels(df.index)
    

    Or you can use matplotlib for plotting, as shown e.g. in this answer.

提交回复
热议问题