This is very good source to learn more about spacings.
However, i have tried to apply the methods shown here for subplots with twin axes, as shown below.
Somehow, it doesnt fit to the entire horizontal spacing of the figure, leaving some empty space.
Does anyone have faced similar issue and know how to solve it?
This is what i have tried:
mosaic = [["A", "A"],
["B", "C"]]
fig = plt.figure(dpi=600)
fig, axs = plt.subplot_mosaic(
mosaic,
layout="constrained",
gridspec_kw={"height_ratios": [1.25, 1],
"width_ratios": [1, 1.5]} # Adjust widths: A = 1, B/C = any vals
)
plt.style.use("dark_background")
plt.suptitle('AQ_20 @ 223K', fontweight = 'bold')
# Titles and labels
axs["B"].set_title("Rocking scan")
axs["B"].set_ylabel("Intensity (a.u.)")
axs["B"].set_xlabel(r"$\Delta_{diffry}$ (deg.)")
axs["C"].set_ylabel("Intensity @ max. (a.u.)")
axs["C"].set_xlabel(r"$t$ (s)")
# Limits
axs["C"].set_xlim(-5, 410)
#axs["C"].set_ylim(1.30, 1.65)
axs["B"].set_xlim(-0.2, 0.2)
#axs["B"].set_ylim(-1, 22)
# axs["A"].set_ylim(2560, 0)
# axs["A"].set_xlim(0, 2160)
axs["A"].set_aspect("auto")
axs["A"].set_title("Local structure @ rocking max")
#axs["A"].axis("off")
axC_twin1 = axs["C"].twinx()
axs["C"].plot([0, 100, 200, 300, 400], [1, 2, 3, 4, 5], label="Primary y-axis", color='blue')
axC_twin1.plot([0, 100, 200, 300, 400], [5, 4, 3, 2, 1], label="Twin y-axis", color='red')
axC_twin2 = axs["C"].twinx()
axC_twin1.plot([0, 100, 200, 300, 400], [2, 2, 2, 2, 2], label="Twin y-axis", color='red')
axC_twin1.set_ylabel("$\Delta_{diffy}$", color='red')
axC_twin2.set_ylabel("FWHM (.deg)", color='green')
axC_twin2.spines['right'].set_position(('outward', 30))