Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scatter plot with scalar data

Tags:

matplotlib

I want to create a scatter plot with matplotlib where the data points have scalar data attached to them and are assigned a color depending on how large their attached value is relative to the other points in the set. I.e., I want something akin to a heatmap. However, I'm looking for a "discrete" heatmap, i.e. nothing should be ploted where there were no points in the original data set and, in particular, no interpolation (in space) should be performed.

Can this be done?

like image 409
Damian Birchler Avatar asked Feb 16 '12 12:02

Damian Birchler


People also ask

What types of data does a scatter plot require?

In order to graph a TI 83 scatter plot, you'll need a set of bivariate data. Bivariate data is data that you can plot on an XY axis: you'll need a list of “x” values (for example, weight) and a list of “y” values (for example, height).

What does a scatter plot with no correlation look like?

If the points on the scatter plot seem to form a line that slants down from left to right, there is a negative relationship or negative correlation between the variables. If the points on the scatter plot seem to be scattered randomly, there is no relationship or no correlation between the variables.


1 Answers

you can use scatter, and set the attached value to 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

like image 65
HYRY Avatar answered Oct 28 '22 06:10

HYRY