Position of axis labels and titles with Plots

Dear julia community,
I am struggling trying to adjust the position of the x and y labels of my plots.

I have a figure made by 4 heatmaps with a nearby colormap:

	plot_xlim_heat = (-3,3)
	plot_xlim_diss = (-5,5)
	# Build the layout
	layout_grid = @layout [grid(2,2) a{0.05w}]

	c_max = max(wf_mol_nlscha..., wf_mol_exact..., wf_diss_nlscha..., wf_diss_exact...)

	N_x_cmap = 101
	x_values = range(0, c_max, N_x_cmap)
	x_values_cmap = ones(N_x_cmap, 1)
	x_values_cmap[:, 1] .= x_values
	x_ticks = Array(0:0.02:c_max)
	colorbar = heatmap([1], x_values, x_values_cmap, legend=:none, xticks=:none, 
			yticks=(x_ticks, string.(x_ticks)))

	h1 = heatmap(x_axis_mol, y_axis_mol, wf_mol_nlscha, aspect_ratio=:equal, 
			xlims=plot_xlim_heat, ylims=plot_xlim_heat, title="NeuroSSCHA - 2a₀",
			xlabel="r₁ [a₀]", ylabel="r₂ [a₀]", legend=:none, bottom_margin=Plots.cm)

	h2 = heatmap(x_axis_exact, x_axis_exact, wf_mol_exact, aspect_ratio=:equal,
			xlims=plot_xlim_heat, ylims=plot_xlim_heat, title="Exact - 2a₀",
			xlabel="r₁ [a₀]", ylabel="r₂ [a₀]", bottom_margin=Plots.cm, legend=:none)
	h3 = heatmap(x_axis_diss, y_axis_diss, wf_diss_nlscha, aspect_ratio=:equal,
			xlims=plot_xlim_diss, ylims=plot_xlim_diss, title="NeuroSSCHA - 4a₀",
			xlabel="r₁ [a₀]", ylabel="r₂ [a₀]", legend=:none)
	h4 = heatmap(x_axis_exact, x_axis_exact, wf_diss_exact, aspect_ratio=:equal,
			xlims=plot_xlim_diss, ylims=plot_xlim_diss, title="Exact - 4a₀",
			xlabel="r₁ [a₀]", ylabel="r₂ [a₀]", legend=:none)
	plot(h1, h2, h3, h4, colorbar,
		layout=layout_grid, dpi=200,

However, the position of the labels of the x and y axis are really far from the actual axis, and I want to get them much closer so I can reduce the margins. I also would like to increase the separation between the title of each figure. Coming from python and matplotlib, I was used to something like:

#adjust y-axis label position
ax.yaxis.set_label_coords(-.1, .5)

#adjust x-axis label position 
ax.xaxis.set_label_coords(.5, -.1)

However, I’m struggling to find an equivalent command that gives me the same kind of flexibility with plots.

Do you know a possible solution?


Did you succeed in reducing the distances from the label to the axes? I have the same problem and would like to reduce my margins.

I am not aware of any way to position the default axis labels in Plots.jl. Of course, you could turn them off and define a custom annotation function based on annotate!().

Usually, after some trial and error, you can get decent results by using Measures and defining subplot margins, along with setting appropriate plot size and dpi parameters. For the former, see one example here.