使用熊猫的箱子图

时间:2017-04-13 05:34:25

标签: python pandas matplotlib

尝试绘制大熊猫数据框的方框图,但x轴列名似乎不清楚。

import matplotlib.pyplot as plt
pd.set_option('display.mpl_style', 'default')
fig, ax1 = plt.subplots()
%matplotlib inline
df.boxplot(column = ['avg_dist','avg_rating_by_driver','avg_rating_of_driver','avg_surge','surge_pct','trips_in_first_30_days','weekday_pct'])

以下是输出

image

如何解决此问题,以便x轴列显示清晰

2 个答案:

答案 0 :(得分:2)

我认为你需要参数rot

cols = ['avg_dist','avg_rating_by_driver','avg_rating_of_driver',
        'avg_surge','surge_pct','trips_in_first_30_days','weekday_pct']

df.boxplot(column=cols, rot=90)

样品:

np.random.seed(100)
cols = ['avg_dist','avg_rating_by_driver','avg_rating_of_driver',
        'avg_surge','surge_pct','trips_in_first_30_days','weekday_pct']
df = pd.DataFrame(np.random.rand(10, 7), columns=cols)
df.boxplot(column=cols, rot=90)

graph

答案 1 :(得分:2)

另一种选择是使盒子的方向水平。

np.random.seed(100)
cols = ['avg_dist','avg_rating_by_driver','avg_rating_of_driver',
        'avg_surge','surge_pct','trips_in_first_30_days','weekday_pct']
df = pd.DataFrame(np.random.rand(10, 7), columns=cols)
df.boxplot(column=cols, vert=False)

enter image description here