我使用contourf在python中生成了一个轮廓图像,如下所示。但是,图像质量存在问题,白色螺纹几乎可以覆盖所有图像。有没有人知道为什么会发生这种情况以及如何解决它?
我用来制作这种图像的代码如下所示。请注意,代码生成四个图像,因为最初的' for'循环,但所有的图像都显示在顶部的白色阴霾,因此我只显示一个。我创建等高线图的部分在最后,所以只能看一下:
import numpy as np
import matplotlib.pyplot as plt
pressure, altitude=np.loadtxt('/home/rb453/information.txt', unpack=True, usecols=[1,3])
altitude=altitude/altitude[0]
Rpl_array=[30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480, 510, 540, 570, 600, 630, 660, 690, 720, 750, 780, 810, 840, 870, 900, 930, 960, 1000]
vel_array=[10000, 12000, 14000, 16000, 18000, 20000, 22000, 24000, 26000, 28000, 30000, 32000, 34000, 36000, 38000, 40000, 42000, 44000, 46000, 48000, 50000]
pressure_thresh=1e5*np.array([10,100,1000, 10000])
pressures = pressure_thresh
max_ablations=[0.175, 0.8, 0.8, 0.9]
dic = dict(zip(pressures, max_ablations))
for p_val in pressure_thresh:
mass_loss_values=[]
for i in range(len(Rpl_array)):
print 'i', i
mass_loss_values_each_rpl=[]
for j in range(len(vel_array)):
altitude_vel_file=np.loadtxt('Rpl_'+str(Rpl_array[i])+'/vel_'+str(vel_array[j])+'.txt', unpack=True, usecols=[2])
x1=np.log10(altitude_vel_file)
y0=np.log10(altitude)
x0=np.log10(pressure)
interpolated_alt=10**(np.interp(np.log10(p_val), x0, y0))
index_value_for_mass_ablation=min(range(len(altitude_vel_file)), key=lambda w: abs(altitude_vel_file[w]-interpolated_alt))
total_mass_ablation_to_p=np.loadtxt('Rpl_'+str(Rpl_array[i])+'/vel_'+str(vel_array[j])+'.txt', unpack=True, usecols=[3])[index_value_for_mass_ablation]
mass_loss_values_each_rpl.append(total_mass_ablation_to_p)
mass_loss_values.append(1-np.array(mass_loss_values_each_rpl))
# produce relvent contour plot
levs = np.linspace(0, dic[p_val], 10000)
fig=plt.figure(p_val)
ax=fig.add_subplot(111)
vel_array=np.array(vel_array)
Rpl_array=np.array(Rpl_array)
XX,YY=np.meshgrid(vel_array, Rpl_array)
mass_loss_values=np.array(mass_loss_values)
cp=ax.contourf(np.array(XX)/1000,YY,mass_loss_values, levels=levs)
fig.colorbar(cp, ax=None)
ax.set_ylabel('Radius (m)')
ax.set_xlabel('Velocity (km/s)')
fig.savefig('outputs/phi0_to_p'+str(int(p_val/1e5))+'bar.pdf')
plt.show()