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?

0

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

5 Comments

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?
Any example how to change the array Z into array x, y, so I can use it in scatter()? Thanks
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?
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?
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

1 Comment

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()?
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.