简体   繁体   中英

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. 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.

Not the direct answer you're looking for but I strongly recommend using Seaborn for the kind of categorical plotting you're doing. (pip install seaborn if you don't have it installed already)

Seaborn's catplot (formerly factorplot) is exactly what you are doing, but with clearer syntax (and prettier plots).

By default catplot has the labeling behavior you are after, which you should be able to achieve with:

import seaborn as sns

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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