# Position of axis labels and titles with Plots

**URL:** https://discourse.julialang.org/t/position-of-axis-labels-and-titles-with-plots/99925
**Category:** Visualization
**Tags:** plots
**Created:** [June 6, 2023, 8:42am UTC](https://discourse.julialang.org/t/position-of-axis-labels-and-titles-with-plots/99925 "2023-06-06T08:42:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mesonepigreco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mesonepigreco/32/46262_2.png) [@mesonepigreco](https://discourse.julialang.org/u/mesonepigreco)
#### Post date: [June 6, 2023, 8:42am UTC](https://discourse.julialang.org/t/position-of-axis-labels-and-titles-with-plots/99925/1 "2023-06-06T08:42:59Z")

</div>

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:

```julia

	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,
		size=(700,650)
	)

```

 ![newplot (1)](https://global.discourse-cdn.com/julialang/original/3X/c/d/cd749b2b4691eef7f2c522c4503c69d2ee12133a.png)

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:

```julia
#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?

---

<div class="post-metadata">

### Author: ![physh](https://avatars.discourse-cdn.com/v4/letter/p/8e8cbc/32.png) [@physh](https://discourse.julialang.org/u/physh)
#### Post date: [December 1, 2023, 5:57am UTC](https://discourse.julialang.org/t/position-of-axis-labels-and-titles-with-plots/99925/2 "2023-12-01T05:57:28Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [December 1, 2023, 8:30am UTC](https://discourse.julialang.org/t/position-of-axis-labels-and-titles-with-plots/99925/3 "2023-12-01T08:30:19Z")

</div>

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](https://discourse.julialang.org/t/space-between-subplots/93897/2).
