0

I am making a density plot using arrays x,y,and z. I want to place the label of the colorbar R0 at a certain location. I present the current and expected outputs.

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

x=np.array([1., 3., 4., 5., 1., 3., 4., 5., 1., 3., 4., 5.])
y=np.array([0.1  , 0.1  , 0.1  , 0.1  , 0.01 , 0.01 , 0.01 , 0.01 , 0.001,
       0.001, 0.001, 0.001])

plt.imshow(z.reshape(3,4), cmap=cm.hot)
cbar=plt.colorbar()
cbar.set_label('R0',loc='top')


plt.xlabel("var",size=20)
plt.ylabel("\u03B2",size=20)

y1=np.unique(y)
y1.sort()

x1=np.unique(x)
x1.sort()

yticklabs = y1
xticklabs = x1

plt.xticks(range(4), xticklabs,size=10)
plt.yticks(range(3), reversed(yticklabs),size=10)

plt.show()

The current output is

enter image description here

The expected output is

enter image description here

0 Answers0