johnhenry
johnhenry

Reputation: 1333

Python - Intensity map without interpolation

I need to make an intensity plot.

I have three lists of x,y,z values, imported from real data: x_list, y_list, z_list. Each of these lists contain 200 values. Therefore there is a corresponding value of z for each x,y couple.

I have tried the following, after some search on the web and another question on StackOverflow:

import numpy as np
import pylab as plt

data = np.loadtxt('data.d')
x_list = data[:,0]
y_list = data[:,1]
z_list = data[:,2]

from scipy.interpolate import interp2d

f = interp2d(x_list,y_list,z_list,kind="linear")

x_coords = np.arange(min(x_list),max(x_list)+1)
y_coords = np.arange(min(y_list),max(y_list)+1)
Z = f(x_coords,y_coords)

fig = plt.imshow(Z,
           extent=[min(x_list),max(x_list),min(y_list),max(y_list)],
           origin="lower")


fig.axes.set_autoscale_on(False)
plt.scatter(x_list,y_list,400,facecolors='none')

plt.show()

This uses interpolation, and I am not sure that it is exactly what I need. Is there a way to plot ONLY the 200 values of z, corresponding to the 200 x,y couples, for which I have a given value, withuot interpolation? Obviously I still need some kind of "intensity relation", I cannot just have a scatter plot without a way of interpreting the "intensity" of the 200 z values.

Upvotes: 0

Views: 1030

Answers (1)

jadsq
jadsq

Reputation: 3382

From what I understand, you want to display xyz points in a 2D graph where z-value would be represented by a color. If that is correct the solution is as simple as stating facecolors=z_list in your scatter plot:

data = np.random.rand(200,3)
x_list = data[:,0]
y_list = data[:,1]
z_list = data[:,2]

plt.scatter(x_list,y_list,200,facecolors=z_list)

plt.colorbar()
plt.show()

Example output : enter image description here

Upvotes: 2

Related Questions