我想把我的情节一年一年地注释在一个分散的情节里。此外,我还想在pandas数据帧中的另一列上标记(添加图例),在本例中是列:ds['label']。我已经设法用这些年来注释分散的数据,但我却被困在如何标记来自不同列的数据上。在

下面是我的示例代码ds

Label Year factor1 factor2 factor3 factor4

0 A 2013 0.318451 0.038893 -0.145478 0.023298

1 B 2013 0.327400 -0.083985 -0.164712 -0.216095

2 C 2013 0.262333 0.251492 0.095186 -0.062729

3 D 2013 0.035074 -0.044357 -0.464473 -0.096461

4 E 2013 0.214464 -0.131810 0.065335 -0.339014

5 F 2013 -0.456510 0.111790 0.358160 0.327663

6 A 2012 0.345147 -0.010345 -0.139058 -0.033598

7 B 2012 0.318605 -0.096974 -0.168039 0.240126

8 C 2012 0.387761 0.145134 0.025229 -0.009165

9 D 2012 -0.007707 -0.033737 -0.401118 0.147932

10 E 2012 0.204582 -0.112144 0.007970 0.367639

11 F 2012 -0.439852 0.128267 0.355429 -0.375302

ds.columnsx=ds['factor2']

y=ds['factor1']

colors = {'A': 'b','B': 'purple', 'C': 'r','D' : 'grey','E' : 'green', 'F' : 'magenta'}

size= 2 *500

x=df['factor2']

y=df['factor1']

labels=df['Year']

fig=figure(1, figsize=(10,8))

ax1 = fig.add_subplot(111)

ax1.scatter(x, y, s=size, alpha=0.7, label=labels, color=[colors[i] for i in ds['Label']])

for label, x, y in zip(labels, x, y):

plt.annotate(label, xy = (x, y),fontsize = 15)

grid(True)

ax1.spines['bottom'].set_color('orange')

ax1.spines['left'].set_color('green')

ax1.xaxis.label.set_color('orange')

ax1.yaxis.label.set_color('green')

ax1.tick_params(axis='x', colors='k')

plt.title('Something', fontsize = 15)

plt.xlabel('Something')

plt.ylabel('Something')

plt.tight_layout()

plt.show()

c3dd0ee1de99391046f492c12bbb5f50.png

Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐