首页 > 解决方案 > 在 hist() 的 python Matplotlib.pyplot 中,我想选择 xlabel 和 ylabel 值

问题描述

我使用了这些库:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

我导入数据,然后选择我想学习的内容

df=df15[['Country','Happiness Score']][0:5]
df

输出是

    Country Happiness Score
0   Switzerland 7.587
1   Iceland 7.561
2   Denmark 7.527
3   Norway  7.522
4   Canada  7.427

之后我想使用 plt.hist() 我想成为 x=Country 和 y=Happiness Score??

标签: pythonmatplotlibdata-visualizationhistogramvisualization

解决方案


直方图用于查看单个变量的分布。在你的情况下是幸福分数。在直方图中将 x 标签作为“国家”是没有意义的。

使用 x=Country 和 y=Happiness Score 时,条形字符会更有意义。


推荐阅读