Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用pandas.DataFrame.plot(kind=';hist';)时,如何交换x轴和y轴?_Python_Pandas_Matplotlib_Histogram - Fatal编程技术网

Python 使用pandas.DataFrame.plot(kind=';hist';)时,如何交换x轴和y轴?

Python 使用pandas.DataFrame.plot(kind=';hist';)时,如何交换x轴和y轴?,python,pandas,matplotlib,histogram,Python,Pandas,Matplotlib,Histogram,我有我的数据框df_power,我想用数据框中Age列的值计数制作一个直方图。我有以下代码: ages = df_power.Age.value_counts().sort_index() age_plot = ages.plot(kind = 'hist', legend = True) age_plot.set_xlabel("Age (Years)") age_plot.set_ylabel("Count") 它给出了以下直方图: 但是如果我使用默认的线图: age_plot =

我有我的数据框
df_power
,我想用数据框中
Age
列的值计数制作一个直方图。我有以下代码:

ages = df_power.Age.value_counts().sort_index()
age_plot = ages.plot(kind = 'hist', legend = True)
age_plot.set_xlabel("Age (Years)")
age_plot.set_ylabel("Count")  
它给出了以下直方图:

但是如果我使用默认的线图:

age_plot = ages.plot(legend = True)
我得到了一个这样的图形(这是我正在寻找的正确的轴方向,但我希望它是直方图形式):


我找不到交换轴的方法,非常感谢任何帮助或解决方案。

请注意,
df.value\u counts().sort\u index().plot(kind='hist',…)
没有多大意义。它正在绘制一个已经用直方图表示的值的直方图。所以它告诉你们,100个年龄值出现在0到500次之间。@importanceofbeinger非常感谢你们,我现在明白了。因此,我应该能够直接从数据帧绘制值的柱状图,而不必对它们进行计数?@ImportanceOfBeingErnest我刚刚尝试了一下,结果非常理想!谢谢你的知识!