简体   繁体   中英

matplotlib imshow how to plot points instead of image?

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?

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

莱娜散点图

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM