0

I'm using this:

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import AxesGrid
plt.rcParams["axes.grid"] = False
import seaborn as sns
from mpl_toolkits.axes_grid1 import make_axes_locatable

a = np.random.random((8, 8))
data = pd.DataFrame([[a],[a],[a],[a]])
fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(nrows=2, ncols=2, figsize = (14,12) ) 
fig.suptitle('my title', fontsize=20)

im1 = ax1.imshow(data[0][0], cmap='plasma', origin='lower', interpolation='nearest', rasterized=True)
divider1 = make_axes_locatable(ax1) 
cax1 = divider1.append_axes("right", size="20%", pad=0.01)
cbar1 = fig.colorbar(im1)
im2 = ax2.imshow(data[0][1], cmap='plasma', origin='lower', interpolation='nearest', rasterized=True)
divider2 = make_axes_locatable(ax2) 
cax2 = divider2.append_axes("right", size="20%", pad=0.01)
cbar2 = fig.colorbar(im2)
im3 = ax3.imshow(data[0][2], cmap='plasma', origin='lower', interpolation='nearest', rasterized=True)
divider3 = make_axes_locatable(ax3) 
cax3 = divider3.append_axes("right", size="20%", pad=0.01)
cbar3 = fig.colorbar(im3)
im4 = ax4.imshow(data[0][3], cmap='plasma', origin='lower', interpolation='nearest', rasterized=True)
divider4 = make_axes_locatable(ax4) 
cax4 = divider4.append_axes("right", size="20%", pad=0.01)
cbar4 = fig.colorbar(im4)
plt.show()

Which is making plots with unusual colorbar ticks (on both sides). How can I get this to look nice or with no numbers on the lefts of the colorbars? Plots with extra ticks

dcpetit
  • 3
  • 3
  • Plot the colorbar on the axis you made for it: `fig.colorbar(im1, cax=cax1)` etc. An [example](https://matplotlib.org/stable/gallery/axes_grid1/demo_colorbar_with_axes_divider.html) in the docs – DavidG Jul 07 '22 at 15:55
  • It is not the same question as redirect states. The comment of @DavidG is useful. The correted code is ``` ... fig, axx = plt.subplots(nrows=2, ncols=2, figsize = (14,12) ) fig.suptitle('my title', fontsize=20) for iax, ax in enumerate(axx.flatten()): im1 = ax.imshow(data[0][0], cmap='plasma', origin='lower', interpolation='nearest', rasterized=True) divider1 = make_axes_locatable(ax) cax1 = divider1.append_axes("right", size="20%", pad="1%") cbar1 = fig.colorbar(im1, cax=cax1) ``` – sherdim Jul 07 '22 at 16:20

0 Answers0