Cupitor
Cupitor

Reputation: 11637

imshow plots with integer axis labels

I am using the labels on axis of an imshow plot as labels for different tests and therefore I want these labels to be real. However I am getting float numbers e.g. 3.5 ,3.0. How can I change this?

Example:

import numpy as np
from matplotlib import pyplot as plt
a=np.random.randn(4,4)
plt.imshow(a,extent=[1,5,1,5],interpolation='none')
plt.show()

enter image description here

Upvotes: 3

Views: 2009

Answers (1)

deinonychusaur
deinonychusaur

Reputation: 7304

Just use an integer array to set the ticks:

plt.xticks(np.arange(1, 6, dtype=np.int))

Upvotes: 2

Related Questions