Home > other >  Group scatterplot by colour from dictionary in matplotlib (python)
Group scatterplot by colour from dictionary in matplotlib (python)

Time:12-31

I have a dictionary of data that I would like to plot. My dictionary is currently structured like so: (# = some number)

data = { '15': [{'x': #, 'y': #}, {'x': #, 'y': #}, etc..], '16': [{'x': #, 'y': #}, {'x': #, 'y': #}, etc..], '17': [{'x': #, 'y': #}, {'x': #, 'y': #}, etc..] }

I am currently looping over each of the key values in the dict and appending the x and y values to a x and y array then plotting x and y

fig, ax = plt.subplots()
ax.scatter(x, y)
plt.show()

I would like to still plot all these x and y points but colour/seperate the points by which key they came from.

For this example dict I would like to have a legend on the plot with the points of different colour with the categories being: '15', '16', '17'

Ive looked up some resources online specifically this link: enter image description here

  • Related