我使用pyplot.imshow使用以下代码显示带有两个最小点的色彩映射表。然而,运行代码,显示黑色的两个最小点但在错误的位置(它们应该在(x1,y1)和(x2,y2))。而且,如果改变t_max,位置也会变化。我做错了什么?
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()
答案 0 :(得分:0)
您混合了X轴和Y轴。有趣的是,我只是answered another question,发生了这个问题。
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(y_axis), len(x_axis)))
for ix, x in enumerate(x_axis):
for iy, y in enumerate(y_axis):
f[iy,ix] = 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()