Pandas xlabel does not show values

前端 未结 2 1465
旧巷少年郎
旧巷少年郎 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:04

    Following should do:

    df1=pd.DataFrame({'config name':['small', 'medium', 'large'], 'value':[-.000127, .000169, -.000206]})
    plt.plot(df1.iloc[:,0], df1.iloc[:,1])
    plt.xlabel('Config name')
    plt.ylabel('Value')
    plt.legend('Value')
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题