2

When making an imshow plot using matplotlib in Python3, half of the upper and lower row is removed once I activate named yticks.

See the example below:

import numpy as np
import matplotlib
import matplotlib.pyplot as plt

dummy_data = np.random.rand(5,8)
ynames = ['one','two','three','four','five']

fig = plt.figure(2)
ax = plt.gca()
im = ax.imshow(dummy_data)
plt.grid(None)

fig = plt.figure(3)
ax = plt.gca()
im = ax.imshow(dummy_data)
ax.set_yticks(np.arange(len(ynames)))
ax.set_yticklabels(ynames)
plt.grid(None)

enter image description here

How do I get back these upper and lower half rows?

  • Didn't find the duplicate when googling, I should have searched for 'heatmap' in stead of 'matshow' and 'imshow'. –  Jan 06 '20 at 13:29

1 Answers1

0

When you set y_ticks it set y limit. Therefore, set ylim again.

ax.set_yticklabels(ynames)
ax.set_ylim(4.5,-0.5)

like this.

enter image description here

shimo
  • 2,156
  • 4
  • 17
  • 21
  • It works, thanks! Still find it odd that it would handle the ylims different from the xlims. When setting x_ticks I do not observe this behaviour. –  Jan 06 '20 at 10:17