2013-04-04 74 views
0

下面是代码:matplotlib imshow如何绘制点而不是图像?

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

它绘制基于数据表z中的一个形象,我怎样才能让它的打印数据点来代替原来的形象?

看起来像需要改变散点图(x,y,...)来绘制数据点,将数组Z改变为x,y有多困难?

回答

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 
1

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

有很多选择,这里取决于你希望看到什么你正在策划什么,但我发现了以下帮助:

Fixing color in scatter plots in matplotlib

+0

Z是这样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]。我可以使用imshow()创建散点图吗? – truelies 2013-04-05 16:11:58

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

scatter plot of lena

+0

是的。我想要分散点。 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]]输入到imshow(z,...)后,结果是一张图片,没有不同点。这是否imshow()插入数据到图片? – truelies 2013-04-05 15:07:02

+0

是的。请参阅http://matplotlib.org/users/image_tutorial.html(对于插值方案:http://matplotlib.org/users/image_tutorial.html#array-interpolation-schemes) – pelson 2013-04-07 09:46:23

+0

任何示例如何将数组Z更改为数组x,y,所以我可以在scatter()中使用它?谢谢 – truelies 2013-04-10 14:41:01

相关问题