0

Here is the code:

plots=imshow(Z,extent=extent,origin,cmap=cmap,aspect='auto',vmin=vmin,vmax=vmax)
plots.plot(Response,component,vrange)

It plots an image based on data list Z, how can I let it print data points instead of an image?

Looks like needs to change to scatter(x, y,...) to plot data points, how difficult it is to change array Z to x, y?

truelies
  • 145
  • 1
  • 2
  • 9

3 Answers3

5

As @jdj081 said, you want to produce a scatter plot.

import os.path

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

# get an image from the sample data directory
fname = os.path.join(matplotlib.get_data_path(), 'sample_data', 'lena.png')
im = plt.imread(fname)

# Reduce the data by a factor of 4 (so that we can see the points)
im = im[::4, ::4]

# generate coordinates for the image. Note that the image is "top down", so the y coordinate goes from high to low.
ys, xs = np.mgrid[im.shape[0]:0:-1, 0:im.shape[1]]

# Scatter plots take 1d arrays of xs and ys, and the colour takes a 2d array,
# with the second dimension being RGB
plt.scatter(xs.flatten(), ys.flatten(), s=4,
            c=im.flatten().reshape(-1, 3), edgecolor='face')
plt.show()

scatter plot of lena

pelson
  • 21,252
  • 4
  • 92
  • 99
  • Yes. I want scatter points. Z includes data like this z [[ 1.09415996 1.43587005 0.89219701 ..., -1.00144994 0.14369801 1.18596005] [ 1.09415996 1.43587005 0.89219701 ..., -1.00144994 0.14369801 1.18596005] ..., [-0.2372447 0.69860512 0.04342676 ..., -0.08253406 -0.51178968 -0.35968387] [-0.27594933 0.54936659 0.32261935 ..., -0.13794966 -0.53104192 -0.35142872]] After input to imshow(z,...), it turns out to be a picture, not different points. Does this imshow() interpolate the data into a picture? – truelies Apr 05 '13 at 15:07
  • Yes. See http://matplotlib.org/users/image_tutorial.html (for interpolation schemes: http://matplotlib.org/users/image_tutorial.html#array-interpolation-schemes) – pelson Apr 07 '13 at 09:46
  • Any example how to change the array Z into array x, y, so I can use it in scatter()? Thanks – truelies Apr 10 '13 at 14:41
  • x and y are the coordinates of Z. So simply doing ``ys, xs = np.mgrid[im.shape[0]:0:-1, 0:im.shape[1]]`` is what you are after isn't it? – pelson Apr 10 '13 at 17:57
  • Looks like change to scatter() not work, it want x, y must be same size, but you know my imshow() picture doesn't have same size. Just wondering why can't plot points using imshow() directly? – truelies Apr 19 '13 at 22:11
1

You didn't provide much information to go on, but it sounds like you really want to create a scatter plot.

There are many options here depending on what you are plotting and what you want to see, but I have found the following helpful:

Fixing color in scatter plots in matplotlib

Community
  • 1
  • 1
jdj081
  • 176
  • 9
  • Z is an array like this z [[ 1.09415996 1.43587005 0.89219701 ..., -1.00144994 0.14369801 1.18596005] [ 1.09415996 1.43587005 0.89219701 ..., -1.00144994 0.14369801 1.18596005]]. Can I create scatter plot using imshow()? – truelies Apr 05 '13 at 16:11
0
import pylab
pylab.figure(1)
pylab.plot([1,2,3,4],[1,7,3,5]) # draw on figure one
pylab.show() # show figure on screen
Luís Ramalho
  • 10,018
  • 4
  • 52
  • 67