Reputation: 1608
I'm writing a code that plots 4 different heatmaps. These heatmaps represents data for each week of the year over 4 years: rows are weeks (first week, second week and so on), columns are my data for the week and each heatmap represents a different year.
As you might notice, the first 3 years have 52 weeks (the whole year) while for the last one (which is 2020) I have data only for the first 30 weeks.
Since I'm plotting these heatmaps to compare them one against each other, I would like to have the last heatmap "cut": instead of having the same exact size of all the others, i would like to align the rows with the other heatmaps (so basically, if compared with the other heatmaps, it will be overall almost half the size of the other, having only 30 rows).
My code so far is the following:
#------getting the data --------
array_2017 = np.array(list_data_years[0]) #[52,200] matrix
#array_2017 = (array_2017 - np.mean(array_2017)) / np.std(array_2017)
array_2018 = np.array(list_data_years[1]) #[52,200] matrix
#array_2018 = (array_2018 - np.mean(array_2018)) / np.std(array_2018)
array_2019 = np.array(list_data_years[2]) #[52,200] matrix
#array_2019 = (array_2019 - np.mean(array_2019)) / np.std(array_2019)
array_2020 = np.array(list_data_years[3]) #[30,200] matrix
#array_2020 = (array_2020 - np.mean(array_2020)) / np.std(array_2020)
----------
#--------plotting--------
fig = plt.figure(figsize=(15,15))
gs0 = gridspec.GridSpec(2,2, figure=fig, hspace=0.2)
ax0 = fig.add_subplot(gs0[0,0])
ax1 = fig.add_subplot(gs0[0,1])
ax2 = fig.add_subplot(gs0[1,0])
ax3 = fig.add_subplot(gs0[1,1])
sns.heatmap(array_2017, ax=ax0, vmin =0, vmax = 2000000)
sns.heatmap(array_2018, ax=ax1, vmin =0, vmax = 2000000)
sns.heatmap(array_2019, ax=ax2, vmin =0, vmax = 2000000)
sns.heatmap(array_2020, ax=ax3,vmin =0, vmax = 2000000)
Upvotes: 0
Views: 915
Reputation: 40697
One easy solution is to pad your array_2020
with NaN so that it has a (52,200) shape
array_2020 = np.pad(array_2020, ((0,52-array_2020.shape[0]),(0,0)), constant_values=np.NaN)
Upvotes: 1