使用 pandas 的方框图
问题描述
正在尝试绘制 pandas 数据框的框图,但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'])
下面是输出
如何修复此问题以使x轴列看起来清晰
解决方案
我认为您需要参数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)
相关文章