import matplotlib.pyplot as plt
import numpy as np
a = np.random.randn(5,5)
plt.imshow(a)
plt.xticks(range(5))
plt.yticks([i-2 for i in range(5)])
plt.show()
results in
??
Also imagine I had 500 instead of 5 ticks, how could I pass the ticks but have less be displayed (for example every 10th)?
CodePudding user response:
Use the extent
parameter, and no need to use xticks
or yticks
:
plt.imshow(a, extent=(-0.5, 4.5, -2.5, 2.5))
Output: