0

I am having a bit of trouble with my output of my code to produce a 2d contour plot. I show the result below. enter image description here

As may be seen, the y axis is greatly distorted, and yet my code seems to have nothing within it which should cause this. My code is shown below:

#vel_array, Rpl_array, and mass_loss_values are all some lists with the same length, but which I have not given here. 

# Set up a regular grid of interpolation points
xi, yi = np.linspace(min(np.array(vel_array)), max(np.array(vel_array)), 100), np.linspace(min(np.array(Rpl_array)), max(np.array(Rpl_array)), 100)
xi, yi = np.meshgrid(xi, yi)

# Interpolate
rbf = Rbf(np.array(vel_array), np.array(Rpl_array), np.array(mass_loss_values), function='cubic')
zi = rbf(xi, yi)
mass_loss_values=np.array(mass_loss_values)
vel_array=np.array(vel_array)
Rpl_array=np.array(Rpl_array)
plt.imshow(zi, vmin=min(mass_loss_values), vmax=max(mass_loss_values), origin='lower',
           extent=[min(vel_array), max(vel_array), min(Rpl_array), max(Rpl_array)])
plt.scatter(np.array(vel_array), np.array(Rpl_array), c=np.array(mass_loss_values))
plt.colorbar()
plt.show()  

I would apprecaite assistance.

4

1 回答 1

1

您的 x 范围为 40000,但 y 范围仅为 1000。

imshow默认情况下将纵横比设置为equal,从而产生非常大的纵横比 (40:1)。尝试在命令中设置aspect='auto'为选项:imshow

plt.imshow(
    zi, 
    vmin=min(mass_loss_values), 
    vmax=max(mass_loss_values),
    origin='lower', 
    extent=[min(vel_array), max(vel_array), min(Rpl_array), max(Rpl_array)], 
    aspect='auto'
    ) 
于 2016-02-29T20:47:51.797 回答