I have some basic car engine size, horsepower and body type data (sample shown below)
body-style engine-size horsepower
0 convertible 130 111.0
2 hatchback 152 154.0
3 sedan 109 102.0
7 wagon 136 110.0
69 hardtop 183 123.0
Out of which I made a scatter plot with horsepower on x axis, engine size on y axis and using body-style as a color scheme to differentiate body classes and. I also used "compression ratio" of each car from a seperate dataframe to dictate the point point size
This worked out well except I cant display color legends for my plot. Help needed as i'm a beginner.
Here's my code:
dict = {'convertible':'red' , 'hatchback':'blue' , 'sedan':'purple' , 'wagon':'yellow' , 'hardtop':'green'}
wtf["colour column"] = wtf["body-style"].map(dict)
wtf["comp_ratio_size"] = df['compression-ratio'].apply ( lambda x : x*x)
fig = plt.figure(figsize=(8,8),dpi=75)
ax = fig.gca()
plt.scatter(wtf['engine-size'],wtf['horsepower'],c=wtf["colour column"],s=wtf['comp_ratio_size'],alpha=0.4)
ax.set_xlabel('horsepower')
ax.set_ylabel("engine-size")
ax.legend()
See Question&Answers more detail:os