简体   繁体   English

用 Pandas 中的 dataframe 值标记散点图的标题

[英]Labelling the title of scatterplots graph with dataframe values in Pandas

I am trying to plot multiple scatterplots using the groupby function to produce separate graphs.我正在尝试使用 groupby function plot 多个散点图来生成单独的图表。 I would like to have a title on each graph with the corresponding Organization Group Code.我想在每个图表上都有一个标题,并带有相应的组织组代码。

OrgGroupPlot = SCPlot.groupby('Organization Group Code')
OrgGroupPlot.plot.scatter('Total Salary', 'Total Benefits', label = SCPlot[['Organization Group Code']])

With this code, I get every single Group Code value on each graph, but not the corresponding one.使用此代码,我可以获得每个图表上的每个组代码值,但不是对应的。 There are supposed to be 7 graphs, so I would like the first graph to have 1 in the title, which is the value of Organization Group Code, and 2 in the second and so forth.应该有 7 个图,所以我希望第一个图的标题中有 1,即组织组代码的值,第二个中的值为 2,依此类推。

Not the direct answer you're looking for but I strongly recommend using Seaborn for the kind of categorical plotting you're doing.不是您正在寻找的直接答案,但我强烈建议您使用 Seaborn 进行您正在做的那种分类绘图。 (pip install seaborn if you don't have it installed already) (pip install seaborn 如果您还没有安装它)

Seaborn's catplot (formerly factorplot) is exactly what you are doing, but with clearer syntax (and prettier plots). Seaborn 的catplot (以前称为 factorplot)正是您正在做的,但语法更清晰(和更漂亮的图)。

By default catplot has the labeling behavior you are after, which you should be able to achieve with:默认情况下, catplot 具有您所追求的标签行为,您应该能够通过以下方式实现:

import seaborn as sns

g = sns.catplot(x='Total Salary', y='Total Benefits', col='Organization Group Code', data=OrgGroupPlot)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM