下面是代碼: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有多困難?
下面是代碼: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有多困難?
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
你沒有提供太多的信息繼續,但它聽起來像你真的想創建一個散點圖。
有很多選擇,這裏取決於你希望看到什麼你正在策劃什麼,但我發現了以下幫助:
正如@ 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()
是的。我想要分散點。 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
是的。請參閱http://matplotlib.org/users/image_tutorial.html(對於插值方案:http://matplotlib.org/users/image_tutorial.html#array-interpolation-schemes) – pelson 2013-04-07 09:46:23
任何示例如何將數組Z更改爲數組x,y,所以我可以在scatter()中使用它?謝謝 – truelies 2013-04-10 14:41:01
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