簡體   English   中英

matplotlib.pyplot imshow() 現在顯示純藍色,不再顯示顏色?

[英]matplotlib.pyplot imshow() now shows a solid blue colour, no longer the colour rendering?

繼我之前提出的問題之后,這里的問題如何在對某些參數進行一些擺弄之后將原點居中在 imshow() 圖的中心,spyder 現在始終顯示空白的藍色輸出。 真是莫名其妙!! 我已經強制 dtype 為 uint8 (我在一個相關問題上讀到了這可能是原因)但無濟於事。

編輯:(感謝快速響應)這里是相關代碼(來自一個更大的程序,用於模擬通過方形孔徑的衍射):

import numpy as np
import matplotlib.pyplot as plt

def expo(x,y,z,xp,yp,k):
    """
    Function of the integrand in Eq. 5
    """
    return np.exp((1j*k/(2*z))*(((x-xp)**2) + ((y-yp)**2))) 

def square_2dsimpson_eval(a,b,n):
    simp_eval = np.zeros((n+1,n+1))
    deltap = (b-a)/n
    xp = 0
    yp = 0
    w = np.zeros((n+1,n+1))
    x=0
    y=0
    for h in range(n+1):    #the first two for loops produce the 2d Simpson matrix of coeffecients
        if h == 0 or h==n:
            w[0,h] = 1

        elif h%2 != 0:
            w[0,h]=4

        elif h%2 == 0:
            w[0,h]=2

    for g in range(n+1):
        if g ==0 or g==n:
            w[g,0]=1

        elif g%2 != 0:
            w[g,0]=4             

        elif g%2 == 0:
            w[g,0]=2

    for h in range(1,n+1):
        for g in range(1,n+1):
            w[h,g]=w[0,h]*w[g,0]

    for h in range(0,n+1):
        xp = h*deltap
        for g in range(0,n+1):
            yp = g*deltap
            simp_eval[h,g] = expo(x,y,z,xp,yp,k) #the integrand

    return (k/(2*np.pi*z))*((deltap**2)/9)*(np.sum(simp_eval*w))

n = 3.3

        #this loop checks that user's N is even as required for Simpson's rule
        while n % 2 != 0:
            n = int(input("Type an even N value: "))
            if n % 2 == 0:
                break
            else:
                print("n must be even you noob!")
        lam=float(input("Type light wavelength in mm: "))
        k=(2*np.pi)/lam
        z=float(input("Type screen distance, z in mm: "))
        rho=float(input("Type rho in mm: "))

        delta = 2/n
        intensity = np.zeros((n+1,n+1),dtype='uint8')
        for i in range(n+1):
            x=-1+(i*delta)
            for j in range(n+1):
                y =-1+(j*delta)
                intensity[i,j] = (abs(square_2dsimpson_eval(-rho/2,rho/2,n)))**2  
        print(intensity.dtype)
        plt.imshow(intensity)
        plt.show()

劇情從此開始: 在此處輸入圖片說明

對此:

在此處輸入圖片說明

提前致謝。

即使 知道生成任一圖像的代碼,我只能說第二張圖像似乎是第一張圖像在沒有數據或數據接近或等於最小值的區域中的剪切圖。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM