1

I have six data arrays (data1, data2, data3, data4, data5 and data6) in my code. An example of an array that I have is below. I would like to increase the hspace after fourth heatmap subplot (see desired image) and plot only one cbar. How can I do them?

data1 = np.array([[2.25, 9.65],
                  [-1.05, -1.50]])

Related part of my code:

values = [data1, data2, data3, data4, data5, data6]
num = [1, 2, 3, 4, 5, 6]
for value, i in zip (values, num):
    ax = plt.subplot(3, 2, i)
    im, cbar = heatmap(value, x, y, ax=ax, cmap="RdBu", cbarlabel="Temperature", vmin=-2, vmax=20)

plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0.1, hspace=0.1)

Desired image:

enter image description here

qasim
  • 427
  • 2
  • 5
  • 14

1 Answers1

1

One horizontal colorbar for seaborn heatmaps subplots and Annot Issue with xticklabelsUsing this as a reference, I set the position of the cbar and created the code.

 import seaborn as sns
 import matplotlib.pyplot as plt
 import pandas as pd
 import numpy as np

 data1 = np.random.random((5,5,))
 data2 = np.random.random((5,5,))
 data3 = np.random.random((5,5,))
 data4 = np.random.random((5,5,))
 data5 = np.random.random((5,5,))
 data6 = np.random.random((5,5,))

 values = [data1, data2, data3, data4, data5, data6]

 fig, axes = plt.subplots(nrows=3,ncols=2, sharex=True, sharey=True)

 im = sns.heatmap(values[0], ax=axes[0,0], cmap="RdBu", cbar=False)
 sns.heatmap(values[1], ax=axes[0,1], cmap="RdBu", cbar=False)
 sns.heatmap(values[2], ax=axes[1,0], cmap="RdBu", cbar=False)
 sns.heatmap(values[3], ax=axes[1,1], cmap="RdBu", cbar=False)
 sns.heatmap(values[4], ax=axes[2,0], cmap="RdBu", cbar=False)
 sns.heatmap(values[5], ax=axes[2,1], cmap="RdBu", cbar=False)

 mappable = im.get_children()[0]
 plt.colorbar(mappable, ax=[axes[1,0],axes[1,1]], orientation = 'horizontal')

enter image description here

r-beginners
  • 31,170
  • 3
  • 14
  • 32