为pandas箱型图(分组)设置无标题

43 投票
8 回答
44824 浏览
提问于 2025-04-18 05:37

在使用pandas绘制箱线图时,如果是根据另一列进行分组,pandas会自动给图表加上一个标题,内容是“根据……分组的箱线图”。有没有办法去掉这个标题呢?我试过使用

suptitle('')

根据这个链接:Pandas: boxplot of one column based on another column

但是这个方法似乎不管用。我现在使用的是最新的pandas版本(0.13.1)。

8 个回答

2

以上提到的解决办法对我都没用,但这个方法有效:

axes = df.boxplot(column=values, by=index, ax=ax, rot=90)
axes.set_title('')

4

在尝试了所有建议之后,只有这个修改对我有效,而且它还允许你修改其他参数:

ax = df.boxplot(by ='value', column =['category'], grid = False);
plt.title('')
plt.suptitle('')
ax.set_title('');
ax.set_xlabel("x_label");
ax.set_ylabel("y_label");
ax = plt.show()
6

在Pandas 1.1.4版本中,这个方法对我有效:

ax = pft[[col, "abuse_marked"]].boxplot(by="abuse_marked", vert=False)
ax.get_figure().suptitle("")

在这里输入图片描述

37

我也遇到过同样的问题。最后我用了这个解决办法

import matplotlib.pyplot as plt    
# df is your dataframe
df.boxplot(column='value', by='category')
title_boxplot = 'awesome title'
plt.title( title_boxplot )
plt.suptitle('') # that's what you're after
plt.show()
42

确保你在正确的图形上使用 suptitle('') 这个命令。

In [23]: axes = df.boxplot(by='g')

In [24]: fig = axes[0][0].get_figure()

In [25]: fig.suptitle('')
Out[25]: <matplotlib.text.Text at 0x109496090>

撰写回答