簡體   English   中英

matplotlib imshow如何繪制點而不是圖像?

[英]matplotlib imshow how to plot points instead of image?

這是代碼:

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有多困難?

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

萊娜散點圖

您沒有提供太多要繼續的信息,但是聽起來您確實想創建散點圖。

根據您要繪制的內容和想要看到的內容,這里有很多選項,但是我發現以下幫助:

在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