Python 为使用熊猫制作的绘图添加标签和标题

Python 为使用熊猫制作的绘图添加标签和标题,python,pandas,plot,Python,Pandas,Plot,我使用以下代码制作了一个简单的直方图: a=['a','a','a','b','b','c','c','d','e','e','e','e'] pd.Seriesa.value_计数。绘制“条形图” 虽然这是一种绘制频率直方图的简明方法,但我不确定如何自定义该图,即: 添加标题 添加轴标签 对x轴上的值进行排序 可以使用matplotlib对其进行自定义。您可以看到我使用.sort\u索引对xlabel进行排序 import matplotlib.pyplot as plt a = ['a',

我使用以下代码制作了一个简单的直方图:

a=['a','a','a','b','b','c','c','d','e','e','e','e'] pd.Seriesa.value_计数。绘制“条形图” 虽然这是一种绘制频率直方图的简明方法,但我不确定如何自定义该图,即:

添加标题 添加轴标签 对x轴上的值进行排序 可以使用matplotlib对其进行自定义。您可以看到我使用.sort\u索引对xlabel进行排序

import matplotlib.pyplot as plt

a = ['a', 'a', 'a', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'e', 'e', 'e', 'e', 'e']
pd.Series(a).value_counts().sort_index().plot(kind='bar')
plt.title('My Title')
plt.xlabel('My X Label')

可以使用matplotlib对其进行自定义。您可以看到我使用.sort\u索引对xlabel进行排序

import matplotlib.pyplot as plt

a = ['a', 'a', 'a', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'e', 'e', 'e', 'e', 'e']
pd.Series(a).value_counts().sort_index().plot(kind='bar')
plt.title('My Title')
plt.xlabel('My X Label')

Series.plot或DataFrame.plot返回matplotlib axis对象,该对象公开了多个方法。例如:

a = ['a', 'a', 'a', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'e', 'e', 'e', 'e', 'e']
ax = pd.Series(a).value_counts().sort_index().plot('bar')
ax.set_title("my title")
ax.set_xlabel("my x-label")
ax.set_ylabel("my y-label")
n、 b:pandas在这里使用matplotlib作为依赖项,并公开matplotlib对象和api。您可以通过导入matplotlib.pyplot作为plt获得相同的结果;ax=plt.子地块1,1,1。如果您一次创建多个绘图,您将找到ax。比模块级plt.title“my title”方便得多,因为它定义了要更改的打印标题,并且可以利用ax对象上的自动完成功能。

Series.plot或DataFrame.plot返回matplotlib axis对象,该对象公开了多种方法。例如:

a = ['a', 'a', 'a', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'e', 'e', 'e', 'e', 'e']
ax = pd.Series(a).value_counts().sort_index().plot('bar')
ax.set_title("my title")
ax.set_xlabel("my x-label")
ax.set_ylabel("my y-label")
n、 b:pandas在这里使用matplotlib作为依赖项,并公开matplotlib对象和api。您可以通过导入matplotlib.pyplot作为plt获得相同的结果;ax=plt.子地块1,1,1。如果您一次创建多个绘图,您将找到ax。比模块级plt.title“my title”方便得多,因为它定义了要更改的绘图标题,并且可以利用ax对象上的自动完成功能。

考虑使用。绘图定制非常容易查看API,通过快速查看,我可以看到1、2和3的正确参数Consider使用。绘图自定义非常容易查看API,通过快速查看,我可以看到1、2和3的正确参数