Reputation: 111
I'm learning how to use the contour function and I was assigned the task of plotting 25 evenly spaced lines using a 4th parameter.
Edit:
This is the desired image:
z = np.load('heights.npy')
plt.contour(np.transpose(z), 25) #Now plotting with 25 evenly spaced contours
plt.title('even contour lines')
plt.savefig('myFig2.png', format='png')
I've checked here and I can't find what I need. Any help would be appreciated thanks.
I've also looked here but as you can see, my lines are not evenly spaced.
Upvotes: 2
Views: 3805
Reputation: 35176
You need to manually specify the levels for your plot, otherwise matplotlib
will determine the levels for you, which is clearly not what you want.
z = np.load('heights.npy')
plt.contour(np.transpose(z),np.linspace(z.min(),z.max(),25))
plt.title('even contour lines')
plt.savefig('myFig2.png', format='png')
This will set the contour
levels such that it divides the span of your z
data to 24 equidistant intervals, giving 25 lines.
Upvotes: 4