我使用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()