[SciPy-user] How to use pcolor and scatter plot in one image?

wierob wierob83 at googlemail.com
Mon Jun 1 05:26:38 EDT 2009


Hi,

thanks for your help. Unfortunately, your example does not work for me. 
The line

histo = np.histogram(z.ravel(), bins=r_[Z.ravel(),2*n**2])

produeces the following error message:

Traceback (most recent call last):
  File "/mnt/VBoxShare/eg.py", line 15, in <module>
    histo = np.histogram(z.ravel(), bins=r_[Z.ravel(),2*n**2])
NameError: name 'r_' is not defined


I'm very new to Scipy and have no idea what your intended to do there.

What I'm trying to do is the following:

from scipy import polyval, zeros
import pylab

a, b = fetch_data(...)
        
pylab.plot(a, b, "g.")	# scatter plot

# regression line
regression = regression_analysis(...)
xr = polyval([regression[0], regression[1]], b)
pylab.plot(b, xr, "r-")

pylab.gca().set_xlim([0,max(b)])
pylab.gca().set_ylim([0,max(a)])


# calculate grid (10x10)

xlim = pylab.gca().get_xlim()[1]
ylim = pylab.gca().get_ylim()[1]
block_x = int(xlim / 10.0 + 1)
block_y = int(ylim / 10.0 + 1)
grid_x = [ block_x * i for i in range(11) ]
grid_y = [ block_y * i for i in range(11) ]

density_map = zeros((10, 10))	# matrix for points per cell

inc = 1.0 / number_of_data_points
    
for i in range(10):
    for j in range(10):
        cell = [ grid_x[i], grid_x[i+1], grid_y[j], grid_y[j+1] ]
        density_map[j][i] += points_in(cell) * inc

# plot the 'density map'
pylab.pcolor(density_map, cmap=pylab.get_cmap("hot"))

pylab.show()


This only creates the scatter plot and the regression line.

kind regards
robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20090601/923cae03/attachment.html>


More information about the SciPy-User mailing list