python - Manually-defined axis labels for Matplotlib imshow() -
the following code:
import matplotlib.pyplot plt import numpy np data = np.random.randint(0, 100, size=(10, 10)) plt.imshow(data, cmap='jet', interpolation='nearest') plt.show()
gives following figure:
however, instead of axis labels corresponding index in array, want manually define them. example, instead of axis labels being (0, 2, 4, 6, 8) above, want them (0, 10, 20, 30 ...).
here code have tried this:
import matplotlib.pyplot plt import numpy np data = np.random.randint(0, 100, size=(10, 10)) labels = range(0, 100, 10) plt.imshow(data, cmap='jet', interpolation='nearest') plt.xticks(labels) plt.yticks(labels) plt.show()
however, gives following figure:
how can achieve figure appearance first one, axis labels second one?
define axes , modify xticklabels, not axis itself. this:
fig, ax1 = plt.subplots(1,1) data = np.random.randint(0, 100, size=(10, 10)) ax1.imshow(data, cmap='jet', interpolation='nearest') ax1.set_xticklabels(['', 0,10,20,30,40])
Comments
Post a Comment