2

How can I add a scale (diameter) legend for the circles in a scatter plotting?

The code below produces some circles, whose diameters are relevant to a parameter.

I'd like to add a legend, similar to legends for maps, in which distances are reported as a horizontal bar with scale or the way around.

import numpy as np
import matplotlib.pyplot as plt

x = np.random.rand(5)
y = np.random.rand(5)
some_relevant_data = [np.random.rand(3) for i in np.random.rand(5)]
some_meaningful_data = np.random.random_integers(100,1000,5)

plt.scatter(x, y, s=some_meaningful_data, c=some_relevant_data, alpha=1)
plt.show()
jwpfox
  • 5,124
  • 11
  • 45
  • 42
Shivid
  • 1,295
  • 1
  • 22
  • 36
  • check ones like :https://stackoverflow.com/questions/39786714/how-to-insert-scale-bar-in-a-map-in-matplotlib – Danii-Sh Dec 06 '17 at 07:43
  • In this case you only get five different sizes of circles, how do you want to handle 10 or 20 or 100 or 1000 different sizes? – Bart Dec 06 '17 at 07:46
  • Thanks @HamedTemsah. kheili aghaii :) – Shivid Dec 06 '17 at 08:01
  • khahesh mikonam azizam :) – Danii-Sh Dec 06 '17 at 08:02
  • @Bart I have to handle some tens of circles, so for my exact case the best way is to use circles' diameters as variable and in some way I would need a relevant legend. After all that legend should provide an intuitive (feeling) result not the exact value of it because it was not the main crucial data to be shown in axis. – Shivid Dec 06 '17 at 08:10
  • Good question, unfortunately, I can only think of quick "hacks" with binning your data in categories and plotting them as individual `scatter()`s. – Bart Dec 06 '17 at 08:38
  • @Hamidreza thanks a lot, dastet dard nakone – Danii-Sh Dec 06 '17 at 11:37
  • Well actually even if I got my solution from there but there the case was the length and in my case its a custom variable (time duration), later I'll update my solution and will be clear that is different and maybe useful. – Shivid Dec 06 '17 at 12:07

0 Answers0