AhmedShaaban AhmedShaaban - 15 days ago 9
Python Question

Python matplotlib uneven spacing y

I am wondering how the y axes has such behavior (uneven spacing) without specifying any thing regarding to the yscale as in the following code.

import numpy as np
import matplotlib.pyplot as plt


d=np.zeros([np.arange(0,8).shape[0],np.arange(0,100).shape[0]])

for i in np.arange(0,8):
for j in np.arange(0,100):
d[i,j]=(i+290)**2+j**2

c=np.array([1000,850,700,500,400,300,250,200])

plt.contourf(np.arange(0,100),c,d);plt.colorbar()
plt.yticks(c,c[::-1])
plt.show()


enter image description here

Thanks

Answer
import numpy as np
import matplotlib.pyplot as plt

d = np.zeros([np.arange(0, 8).shape[0], np.arange(0, 100).shape[0]])

for i in np.arange(0, 8):
    for j in np.arange(0, 100):
        d[i, j] = (i + 290) ** 2 + j ** 2
l = [1000, 850, 700, 500, 400, 300, 250, 200]
r = [l[-1] + l[0]-x for x in l]
c = np.array(l)
e = np.array(r)

plt.contourf(np.arange(0, 100), c, d)
plt.colorbar()
plt.yticks(e, c)
plt.show()

enter image description here