简体   繁体   English

matplotlib imshow如何绘制点而不是图像?

[英]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? 它根据数据列表Z绘制图像,如何让它打印数据点而不是图像?

Looks like needs to change to scatter(x, y,...) to plot data points, how difficult it is to change array Z to x, y? 看起来需要更改为散点图(x,y,...)以绘制数据点,将数组Z更改为x,y有多困难?

As @jdj081 said, you want to produce a scatter plot. 正如@ jdj081所说,您想要生成一个散点图。

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 在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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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