0
我正在使用pyplot.imshow以下面的代碼顯示帶有兩個最小點的顏色映射。然而,運行代碼顯示了黑色的兩個最小點,但是位置錯誤(它們應該在(x1,y1)和(x2,y2))。更重要的是,如果改變t_max,位置也會有所不同。我究竟做錯了什麼?根據繪製的值的範圍,在Python中繪製顏色映射會意外改變?
import numpy
import matplotlib.pyplot as pyplot
import matplotlib.cm as cm
a = 0.1
b = 4
X = 1.1*10**7
x1, y1 = 36, 48*numpy.pi/32
x2, y2 = 49, 57*numpy.pi/32
d1 = (-101872 + X - (X - 2122) * (1+(a*(x1-x2)**2 + (b*(y1-y2))**2)))/((1/(1+(a*(x2-x1)**2 + (b*(y2-y1))**2))) - (1+(a*(x1-x2)**2 + (b*(y1-y2))**2)))
d2 = (X - d1 - 2122)*(1+(a*(x1-x2)**2 + (b*(y1-y2))**2))
def E_density(x, y):
return X - d1/(1+(a*(x-x1)**2 + (b*(y-y1))**2)) - d2/(1+(a*(x-x2)**2 + (b*(y-y2))**2))
t_min, t_max = 14, 104
phi_min, phi_max = 47*numpy.pi/32, 61*numpy.pi/32
dt = 1
dphi = numpy.pi/128
x_axis = numpy.arange(t_min, t_max, dt)
y_axis = numpy.arange(phi_min, phi_max, dphi)
f = numpy.zeros((len(x_axis), len(y_axis)))
for ix, x in enumerate(x_axis):
for iy, y in enumerate(y_axis):
f[ix, iy] = E_density(x, y)
fig1 = pyplot.figure()
im = pyplot.imshow(f, extent = (t_min, t_max, phi_min, phi_max), origin = 'lower', cmap = cm.gray, aspect = 'auto', vmin = 0, vmax = 10**7)
pyplot.colorbar(im, orientation = 'vertical')
pyplot.show()