我正在使用matplotlib绘制等高线图。我的输出如下: -
我想要输出如下:
您可以清楚地看到轮廓线更加平滑。我怎样才能做到这一点?
我的代码:
import numpy as np
import matplotlib.pyplot as plt
import scipy.interpolate
fig, ax = plt.subplots()
with open("533_12.pmf", "r") as f:
x = []
y = []
z = []
for line in f:
if not line.strip() or line.startswith('@') or line.startswith('#'):
continue
row = line.split()
x.append(float(row[0]))
y.append(float(row[1]))
z.append(float(row[2]))
x = np.asarray(x)
y = np.asarray(y)
z = np.asarray(z)
print "x = ", x
print "y = ", y
print "z = ", z
# Set up a regular grid of interpolation points
nInterp = 1000
xi, yi = np.linspace(x.min(), x.max(), nInterp), np.linspace(y.min(), y.max(), nInterp)
xi, yi = np.meshgrid(xi, yi)
zi = scipy.interpolate.griddata((x, y), z, (xi, yi), method='cubic')
plt.imshow(zi, vmin=z.min(), vmax=z.max(), origin='lower',
extent=[x.min(), x.max(), y.min(), y.max()], aspect='auto')
ax.contour(xi, yi, zi, colors='k')
plt.xlabel("Distance(Angstorm)")
plt.ylabel("Dihedral Angle")
plt.colorbar()
plt.show()