I am trying to plot two 3D wireframe plot and a colorbar in one one row within a single figure. In order to apply color ramp on the wireframe I followed this Stackoverflow Answer. I had to generate independent colorbar because of this. Since I am using tight_layout
the colorbar is consuming the entire height and appearing with large width.
So far I could not find any solution to control the size of the colorbar. I tried changing the width_ratio
of the grid but the width remains unchanged. It seems the height can not be adjusted in the tight layout
.
My Code for plotting is given below. I will be grateful for any help in this regard.
def plot_signature(hh, hv, vh, vv, wireframe=False):
x_c, y_c, z_c = synthesize(hh=hh, hv=hv, vh=vh, vv=vv, channel=False)
x_x, y_x, z_x = synthesize(hh=hh, hv=hv, vh=vh, vv=vv, channel=True)
xticks = np.linspace(0, 180, 13)
yticks = np.linspace(-45, 45, 7)
zticks = np.linspace(0, 1, 11)
xt_labels = np.core.defchararray.add(xticks.astype(int).astype(str), u"\u00b0")
yt_labels = np.core.defchararray.add(yticks.astype(int).astype(str), u"\u00b0")
plt.ion()
fig = plt.figure(tight_layout=True)
grid = fig.add_gridspec(nrows=1, ncols=3, width_ratios=[1, 10, 10])
ax_cbar = fig.add_subplot(grid[0, 0])
ax_cpol = fig.add_subplot(grid[0, 1], projection='3d')
ax_xpol = fig.add_subplot(grid[0, 2], projection='3d')
ax_cpol.set_xlim([0, 180])
ax_cpol.set_ylim([-45, 45])
ax_cpol.set_zlim([0, 1])
ax_xpol.set_xlim([0, 180])
ax_xpol.set_ylim([-45, 45])
ax_xpol.set_zlim([0, 1])
cfont = {'fontname':'CMU Serif'}
color_map = cm.rainbow
if wireframe:
norm_c = plt.Normalize(z_c.min(), z_c.max())
norm_x = plt.Normalize(z_x.min(), z_x.max())
colors_c = color_map(norm_c(z_c))
colors_x = color_map(norm_c(z_x))
rcount_c, ccount_c, _ = colors_c.shape
rcount_x, ccount_x, _ = colors_x.shape
pfig_c = ax_cpol.plot_surface(x_c, y_c, z_c, rcount=rcount_c, ccount=ccount_c, facecolors=colors_c, shade=False)
pfig_x = ax_xpol.plot_surface(x_x, y_x, z_x, rcount=rcount_x, ccount=ccount_x, facecolors=colors_x, shade=False)
pfig_c.set_facecolor((0, 0, 0, 0))
pfig_x.set_facecolor((0, 0, 0, 0))
else:
ax_cpol.plot_surface(x_c, y_c, z_c, cmap=color_map, linewidth=0, antialiased=True)
ax_xpol.plot_surface(x_x, y_x, z_x, cmap=color_map, linewidth=0, antialiased=True)
ax_cpol.set_xticks(xticks)
ax_xpol.set_xticks(xticks)
ax_cpol.set_xticklabels(xt_labels)
ax_xpol.set_xticklabels(xt_labels)
ax_cpol.set_yticks(yticks)
ax_xpol.set_yticks(yticks)
ax_cpol.set_yticklabels(yt_labels)
ax_xpol.set_yticklabels(yt_labels)
ax_cpol.set_xlabel('Orientation Angle ($\psi$)', labelpad=16, fontsize=16, **cfont)
ax_xpol.set_xlabel('Orientation Angle ($\psi$)', labelpad=16, fontsize=16, **cfont)
ax_cpol.set_ylabel('Ellipticity Angle ($\chi$)', labelpad=16, fontsize=16, **cfont)
ax_xpol.set_ylabel('Ellipticity Angle ($\chi$)', labelpad=16, fontsize=16, **cfont)
ax_cpol.set_zlabel("Relative Intensity", labelpad=16, fontsize=16, **cfont)
ax_xpol.set_zlabel("Relative Intensity", labelpad=16, fontsize=16, **cfont)
ax_cpol.set_zticks(zticks)
ax_xpol.set_zticks(zticks)
ax_cpol.set_title("Co-pol Signature", fontsize=20, pad=20, **cfont)
ax_xpol.set_title("Cross-pol Signature", fontsize=20, pad=20, **cfont)
cb_norm = mpl.colors.Normalize(vmin=0,vmax=1)
cb_ticks = np.linspace(0.0, 1.0, 11)
cb = mpl.colorbar.ColorbarBase(
ax_cbar,cmap=color_map,
norm=cb_norm,ticks=cb_ticks,
label='Color Map',
orientation='vertical'
)
cb_label = cb.ax.yaxis.label
cb.ax.yaxis.labelpad = 10
custom_font = mpl.font_manager.FontProperties(family='CMU Serif', size=12)
cb_label.set_font_properties(custom_font)
plt.show()
Currently the plot looks like the following:
However, I want it to be something like below: