Scatter plot with scalar data

I want to create a scatter plot with matplotlib where the data points have scalar data attached to them and they are assigned a color depending on how large their attached value is relative to other points in the set. I want something like a heatmap. However, I am looking for a β€œdiscrete” heatmap, i.e. Nothing should be indicated if there were no points in the original dataset, and in particular interpolation (in space) should not be performed.

Can this be done?

+6
source share
2 answers

you can use the scatter and set the applied value to the c parameter:

import numpy as np import pylab as pl x = np.random.uniform(-1, 1, 1000) y = np.random.uniform(-1, 1, 1000) z = np.sqrt(x*x+y*y) pl.scatter(x, y, c=z) pl.colorbar() pl.show() 

enter image description here

+10
source

The solution to this is Altair.

 import numpy as np import pylab as pl x = np.random.uniform(-1, 1, 1000) y = np.random.uniform(-1, 1, 1000) z = np.sqrt(x*x+y*y) df = pd.DataFrame({'x':x,'y':y, 'z':z}) from altair import * Chart(df).mark_circle().encode(x='x',y='y', color='z') 

enter image description here

-1
source

Source: https://habr.com/ru/post/908612/


All Articles