everyone,
I have problem when I tried to adjust colorbar to the same height with figure. I know little about the intrinsic mechanism of data visualization, or axis, fig or something like that. my code is following, sorry for unloading images,
For Figure(1), notice that input data is square, i.e., 51 by 51. The figure is satisfying. import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.axes_grid1 import make_axes_locatable
plt.cla()
plt.clf()
fig1 = plt.figure(1)
ax0 = plt.subplot()
im0 = ax0.imshow(np.arange(51*51).reshape((51,51)), cmap="hsv")
divider0 = make_axes_locatable(ax0)
ax_cb0 = divider0.append_axes("right", size="2%", pad=0.05)
fig1.add_axes(ax_cb0)
plt.colorbar(im0, cax=ax_cb0)
plt.savefig("tmp0.png", bbox_inches="tight")
For figure (2), the code is following, notice that now the input data is 51 by 501, the output is not satisfying,
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable
plt.cla()
plt.clf()
fig2 = plt.figure(2)
ax1 = plt.subplot()
im1 = ax1.imshow(np.arange(51*501).reshape((51,501)), cmap="hsv")
divider1 = make_axes_locatable(ax1)
ax_cb1 = divider1.append_axes("right", size="2%", pad=-4)
fig2.add_axes(ax_cb1)
plt.colorbar(im1, cax=ax_cb1)
ax1.set_aspect(4)
plt.savefig("tmp1.png", bbox_inches="tight")
but still, we can make it better by manually adjusting pad parameter in this line
ax_cb0 = divider0.append_axes("right", size="2%", pad=0.05)
but which is absolutely not the recommended way, COULD anyone know the smart way of doing it or smart way of estimating the value of pad parameter? Thanks in advance.