在matplotlib中从 pandas 系列绘制线图时显示分类的x轴值 [英] Show categorical x-axis values when making line plot from pandas Series in matplotlib

查看:107
本文介绍了在matplotlib中从 pandas 系列绘制线图时显示分类的x轴值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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', 'c'])
s.plot()
plt.show()

推荐答案

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

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

输出:

这篇关于在matplotlib中从 pandas 系列绘制线图时显示分类的x轴值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆