【问题标题】:Show categorical x-axis values when making line plot from pandas Series in matplotlib在 matplotlib 中从熊猫系列制作线图时显示分类 x 轴值
【发布时间】:2018-04-22 22:20:56
【问题描述】:

如何显示 [a, b, c] 的 x 轴值?

import pandas as pd
import matplotlib.pyplot as plt

s = pd.Series([1, 2, 10], index=['a', 'b', 'c'])
s.plot()
plt.show()

【问题讨论】:

    标签: python pandas matplotlib


    【解决方案1】:

    您可以使用plt.xticks 显示您的 xtick 标签:

    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()
    

    输出:

    【讨论】:

    • 先生,您是救生员!我永远不会想到这一点!
    猜你喜欢
    • 2018-12-11
    • 2017-12-09
    • 1970-01-01
    • 1970-01-01
    • 2015-01-11
    • 2021-11-14
    • 2018-07-19
    • 2014-10-30
    • 2015-04-04
    相关资源
    最近更新 更多