You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Matplotlib为图表条目分组并添加统一括号标识

如何使用Matplotlib为图表条目分组并添加统一括号标识

我目前还没找到能解决我问题的方法,具体情况如下:

我有多组数据条目:

  • A, B, C 属于名为“Letters”的分组
  • 单独的符号I被标注为I-Roman number
  • 1, 2, 3 属于“Arabic numbers”分组

我现在使用的代码如下:

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('Test.csv', sep=';')
df.head()
print(df)

#df.plot(x="nameEntry", y="valueEntry", kind="bar")
#plt.show()

fig, ax = plt.subplots()

ax.bar(df["nameEntry"], df["valueEntry"])
fig.subplots_adjust(bottom=0.28)
plt.xticks(rotation=45)
plt.show()

当前这段代码生成的柱状图里,所有条目都是单独排列的,没有任何分组相关的标识。

但我想要实现的效果是:将A、B、C用统一的标识(不一定是大括号,任何能体现分组的标记都可以)归为“Letters”组,1、2、3归为“Arabic numbers”组,用类似大括号的标记把同组的条目连接起来,同时在标记旁标注分组名称,让每组的归属关系清晰可见。

请问用Matplotlib能不能通过编程实现这种分组标识的效果?

我使用的数据集如下:

nameEntry;valueEntry
A;45216
B;21739
C;32179
I - Roman number;73218
1;819023
2;291
3;38910

备注:内容来源于stack exchange,提问作者user2919828

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 14:44:36