0

I'm trying to create a scatter plot, but the auto-created legend is out from range (0...100). 120% label in legend.

sns.scatterplot(data=df1,x='x',y='y',hue='percent',ax=ax1)

I tried to pass list of labels:

plt.legend(labels=[0.0,0.25,0.5,0.75,1.0])

But it still doesn't look good:

link

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • Dataset has a lot of unique percent value, so I can't use this parameter: legend : "full" – Nikolay Andreev Jul 13 '19 at 09:22
  • Since you seem to be new to Stack Overflow, you should read [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Sheldore Jul 13 '19 at 11:16
  • It'd be good to see which values does the `percent` feature have. Are you sure its data is correct? – 89f3a1c Jul 14 '19 at 03:49
  • Welcome to Stack Overflow! Are you interested in something like this? https://stackoverflow.com/questions/6063876/matplotlib-colorbar-for-scatter – Zaya Jul 14 '19 at 05:04
  • @89f3a1c, I'm sure. Data is correct - [link](https://imgur.com/a/mLD2K8e) – Nikolay Andreev Jul 14 '19 at 14:48
  • 1
    Wow, @Zaya, I didn't know about colorbar :D Graph looks much better with it, than that legend I tried to do. Thanks a lot! – Nikolay Andreev Jul 14 '19 at 15:10
  • @Zaya, Post your comment as answer, I' ll accept it. – Nikolay Andreev Jul 14 '19 at 15:17

1 Answers1

2

Matplotlib's colorbar is a great way to depict a range of values on a scatterplot. Example.

Zaya
  • 508
  • 4
  • 8