Brian B.
Brian B.

Reputation: 111

Matplotlib evenly spaced contour lines

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: enter image description here

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')

enter image description here

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

Answers (1)

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

Related Questions