Note that there are some explanatory texts on larger screens.

plurals
  1. POimshow and histogram2d: can't get them to work
    text
    copied!<p>I'm learning Python and this is my first question here. I've read other topics related to the usage of <strong>imshow</strong> but didn't find anything useful. Sorry for my bad English.</p> <p>I have plotted a set of points here, left graphic:</p> <p><a href="https://dl.dropbox.com/u/10411539/python/image.png" rel="noreferrer">points (left) and image (right)</a></p> <p>Now I'd like to see an image of the density of points, so I used <strong>imshow</strong> and <strong>histogram2d</strong>, and I got the image to the right in the previous link.</p> <p>The image doesn't correspond to the distribution of points. How is this possible? I've followed the instructions in the help and even changed some parameters but nothing worked :( </p> <p>The code is:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt import matplotlib.cm as cm j, h, k = np.loadtxt("test.dat", usecols=(2, 4, 6), \ unpack=True) # límites xmin = -0.5 xmax = 3.0 ymin = -0.5 ymax = 4.0 # colores j_h = j - h h_k = h - k # no todas las estrellas son graficadas x1 = 0.5 y1 = 0.5 b = 2.2 c = y1 - b * x1 x = y = np.array([]) for xi, yi in zip(h_k, j_h): if xi &lt; (yi - c) / b: x = np.append(x, xi) y = np.append(y, yi) # gráfico fig = plt.figure(figsize=(8, 7)) ax = fig.add_subplot(111) #ax.plot(x, y, "go") ax.set_xlabel(r"X", fontsize=14) ax.set_ylabel(r"Y", fontsize=14) ax.axis([xmin, xmax, ymin, ymax]) # imagen rango = [[xmin, xmax], [ymin, ymax]] binsx = int((xmax - xmin) / 0.05) binsy = int((ymax - ymin) / 0.05) binsxy = [binsx, binsy] H, xedges, yedges = np.histogram2d(x, y, range=rango, bins=binsxy) extent = [yedges[0], yedges[-1], xedges[0], xedges[-1]] cp = ax.imshow(H, interpolation='bilinear', extent=extent, cmap=cm.jet) fig.colorbar(cp) plt.show() </code></pre> <p>The links for the data used is here:</p> <p><a href="https://dl.dropbox.com/u/10411539/python/test.dat" rel="noreferrer">https://dl.dropbox.com/u/10411539/python/test.dat</a></p> <p>Any help is appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload