2

I am using matplotlib to plot a contour plot. My output look like this :-

enter image description here

I want the output which looks like this :

enter image description here

You can clearly see the contour lines are more smooth. How can I achieve that ?

My Code :

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()
Grayrigel
  • 3,474
  • 5
  • 14
  • 32

0 Answers0