[SciPy-user] How to use pcolor and scatter plot in one image?
Sun May 31 07:10:19 CDT 2009
could you give a little more details about what you're doing? If your
problem is specifically a plot issue, you should rather write to the
matplotlib mailing-list (http://sourceforge.net/mail/?group_id=80706).
I tried to reproduce what you describe and as far as I'm concerned, I
don't have any problem plotting on the same figure a scatter plot of the
data and a grid of the coarsened density of points. See below for the
code I used. Is it what you want to do?
import numpy as np
import pylab as pl
N = 1000
n = 10
np.random.seed(3)#use always the same seed
x, y = np.random.randn(2, N)/10 +0.5
X, Y = np.mgrid[0:1:n*1j, 0:1:n*1j]
xfloor = X[:,0][np.floor(n*x).astype(int)]
yfloor = Y[np.floor(n*y).astype(int)]
z = xfloor + n*yfloor
Z = X + n*Y
histo = np.histogram(z.ravel(), bins=r_[Z.T.ravel(),2*n**2])
pl.pcolor(X-1./(2*n), Y-1./(2*n), histo.reshape((n,n))) #shifted to
# have centered bins
On Sun, May 31, 2009 at 12:59:23PM +0200, wierob wrote:
> how can I use pcolor and a scatter plot in one image?
> I have a scatter plot where a lot of data points are so close to each
> other that they are drawn as (almost) one point in the scatter plot. So
> I'm trying to visualize which area of the scatter plot contains the most
> data points. Using pcolor I can draw a gird where each cell visualizes
> the relative number of data points by a different color.
> If I try to draw the scatter plot and the grid in the same image, only
> the scatter plot will be drawn. Regardless of the invocation order of
> plot and pcolor.
> Both return only the scatter plot.
> I'm new to Scipy. What am I doing wrong?
> Thanks in advance.
> kind regards
> SciPy-user mailing list
More information about the SciPy-user