Issue
I have a dataframe and trying to plot separate scatterplots for each Organization Group Code using MatPlotLib. I get the graph output combines and overlaps each other.
Here's my plotting code
import matplotlib.pyplot as plt
PubProtect = SCPlot[SCPlot['Organization Group Code'] == 1]
x1 = PubProtect['Total Salary']
y1 = PubProtect['Total Benefits']
area1 = 5
plt.scatter(x1, y1, area1, alpha=0.5)
PubWorks = SCPlot[SCPlot['Organization Group Code'] == 2]
x2 = PubWorks['Total Salary']
y2 = PubWorks['Total Benefits']
colors = PubWorks[['Total Salary']].count()
area2 = 5
plt.scatter(x2, y2, area2, alpha=0.5)
How do I separate both graphs?
Solution
You may want to check out Pandas plotting functionalities, for example df.plot.scatter
In this case you can group your DataFrame by Organization Group Code and make a scatter plot for each Code.
grouped = SCPlot.groupby('Organization Group Code')
grouped.plot.scatter('Total Salary', 'Total Benefits')
This will generate a seperate graph for each group code
Answered By - Mekhi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.