Show categorical x-axis values when making line plot from pandas Series in matplotlib

前端 未结 1 1848
心在旅途
心在旅途 2020-12-21 04:37

How do I get the x-axis values of [a, b, c] to show up?

import pandas as pd
import matplotlib.pyplot as plt

s = pd.Series([1, 2, 10], index=[\'a\', \'b\', \         


        
相关标签:
1条回答
  • 2020-12-21 05:10

    You can get your xtick labels to show using plt.xticks:

    import pandas as pd
    import matplotlib.pyplot as plt
    s = pd.Series([1, 2, 10], index=['a', 'b', 'c'])
    s.plot()
    plt.xticks(np.arange(len(s.index)), s.index)
    plt.show()
    

    Output:

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