0

这是代码:

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

它根据数据列表 Z 绘制图像,我怎样才能让它打印数据点而不是图像?

看起来需要更改为 scatter(x, y,...) 来绘制数据点,将数组 Z 更改为 x, y 有多难?

4

3 回答 3

5

正如@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()

莉娜的散点图

于 2013-04-05T09:27:16.940 回答
1

您没有提供太多信息,但听起来您真的想创建一个散点图。

这里有很多选项,具体取决于您正在绘制的内容和您想要看到的内容,但我发现以下内容很有帮助:

修复matplotlib中散点图中的颜色

于 2013-04-04T23:13:50.277 回答
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
于 2013-04-04T23:13:44.747 回答