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:

enter image description here

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:

enter image description here

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

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -