简体   繁体   English

在matplotlib中从pandas系列制作线图时显示分类x轴值

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

How do I get the x-axis values of [a, b, c] to show up? 如何显示[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()

在此输入图像描述

You can get your xtick labels to show using plt.xticks : 您可以使用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()

Output: 输出:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM