Tweak axes labels of a 3d plot

I notice that when I make a 3d plot using Plots, the x and y axes labels are tilted so that they are parallel to the axes. I would like to make them horizontal.
What attributes in Plots.jl control the tilting of the axes labels for 3d plots?

Also, I would like to make the z axis label appear to the left of the plot, so that it does not overlap with the colourmap. What is the corresponding attribute in Plots.jl?

The help is appreceated.

1 Like

Please post an example that shows what you mean.

fig

Ok. Here is a plot itself. Interesting thing, this tilting occurs if use Julia 1.1.0. However, there is no tilting if I use Julia 1.3.0. May be it has something to do with the different versions of Plots.jl.

1 Like

The current stable version of Julia is 1.5.2. Could you please post the output with that version?

fig_ver2

Here is the output for Julia 1.5.2.
Now I have a new question: how do I adjust the position of the axes labels so that they do not overlap with the tick labels?
Also, How do I put z axis label to the left of the plot? And how do I rotate it by 90 degrees?
(I am curious if there are the corresponding attributes in Plots.jl. If there are not, I guess I should better stick with PyPlot.jl)

It would be helpful to have the source code too.

Here is an example to play with:

using Plots
pyplot()

f(x,a) = 1/x + a*x^2

xs = collect(0.1:0.05:2.0);
as = collect(0.2:0.1:2.0);

x_grid = [x for x in xs for y in as];
a_grid = [y for x in xs for y in as];

p = plot(x_grid, a_grid, f.(x_grid,a_grid), st = :surface, xlabel = "xlabel", ylabel = "ylabel", zlabel = "zlabel")

The result that I get looks like this:
somefig.

As you may notice, label for ‘y’ axis is a bit close to the tick labels. Label for ‘z’ axis overlaps with the colorbar: I either need to move the label to the left side of the plot, or the colorbar. Also, I would like to rotate the label for ‘z’ axis by 90 degrees. Also, the colorbar itself does not have any tick labels for some strange reason. How do I add them?

Are there Plots.jl attributes to control this behaviour, or I need to resort to using PyPlot.jl directly?

GR (the default backend) seems to do exactly what you specify:

I don’t know if you are familiar with Gnuplot, but with that you can do anything (almost). Take a look.

using Gnuplot
f(x,a) = 1/x + a*x^2
xs = 0.1:0.05:2.0
as = 0.2:0.1:2.0
fxy = [f(x,a) for x in xs, a in as]

@gsp "set xyplane at 0" "set auto fix" "set grid" :-
@gsp :- xlab = "xlabel" ylab = "ylabel" zlab = "zlabel" cblabel = "f(x,a)" :-
@gsp :- "set zlabel font ',12' textcolor 'red' rotate by 90" :- # the same can be done for all other labels. 
@gsp :- xs as fxy "w pm3d" "set view 55, 65" "set key off"
save(term="pngcairo size 450,400 fontscale 0.8", output="example3DLabels.png")

example3DLabels

Looks great. The only downside is that gnuplot version does not look as high quality as pyplot and gr versions. May be it is because the picture is png with low resolution?

Unfortunately, I still run into problems with the labels when using Plots with the gr() backend, especially with longer labels. So, the question remains: How can you manually adjust the placement of the labels? I haven’t found any solution to this using Plots yet.

  • I can see that Gnuplot offers a solution, but that should also be possible in Plots.

jl v1.5.2
Plots v1.6.10

using Plots
gr()

f(x,a) = 1/x + a*x^2
xs = collect(0.1:0.05:2.0);
as = collect(0.2:0.1:2.0);

x_grid = [x for x in xs for y in as];
a_grid = [y for x in xs for y in as];

plot(x_grid, a_grid, f.(x_grid,a_grid),
        st = :surface,
        xlabel = "longer xlabel",
        ylabel = "longer ylabel",
        zlabel = "longer zlabel")

For the above code snippet I get:

test

1 Like
using Gnuplot
f(x,a) = 1/x + a*x^2
xs = 0.1:0.05:2.0
as = 0.2:0.1:2.0
fxy = [f(x,a) for x in xs, a in as]

@gsp "set xyplane at 0" "set auto fix" "set grid" :-
@gsp :- xlab = "longer xlabel" ylab = "longer ylabel" zlab = " longer zlabel" cblabel = "f(x,a)" :-
@gsp :- "set zlabel font ',12' textcolor 'red' rotate by 90" :- # the same can be done for all other labels. 
@gsp :- "set xlabel offset -3,0,0" :- # position of xlabel
@gsp :- xs as fxy "w pm3d" "set view 55, 65" "set key off"
save(term="pdf size 5.5,5.5", output="example3DLabels.pdf")

This will be fixed again by https://github.com/JuliaPlots/Plots.jl/pull/3074.

1 Like