Greg Brewster
Greg Brewster

Reputation: 47

How to add a legend to a scatter graph?

I have plotted a scatter graph that takes two columns from a table using:

df.plot.scatter("volume/mm^3", "Cost per m^3/$") 
plt.title("Volume vs. Cost Analysis", size = 16)
plt.ylim((0,80000))
plt.xlim((7500,30000))

I am now trying to either annotate each point or create a legend using the first column How would I do so?

Upvotes: 2

Views: 76

Answers (1)

piRSquared
piRSquared

Reputation: 294198

Use the label parameter

df = pd.DataFrame(np.random.rand(10, 2), columns=['x', 'y'])

df.plot.scatter('x', 'y', label='x')

enter image description here

Upvotes: 3

Related Questions