juliacentertitletext-alignmentpgfplots

Title left alignment with PGFPlots in Julia


I use PGFPlots.jl package in Julia to produce figures. I would like to have the title of figure being left aligned [instead of being centered by default]. Here is my MWE in Julia language:

using PGFPlots
p = Plots.Linear3(rand(10), rand(10), rand(10), mark = "none")
Axis(p, title = "(a)")

The title of the obtained figure is aligned center by default. How could I modify the above Julia code to have the title "(a)" being left aligned?

Thank you in advance.


Solution

  • The PGFPlots.Axis offers the keyword argument style, where you can paste options for pgfplots.

    In your case, you can anchor the title at the top left (i.e., north west) of the bounding box.

    using PGFPlots
    p = Plots.Linear3(rand(10), rand(10), rand(10), mark = "none")
    a = Axis(p, title="(a)", style="title style={at={(current bounding box.north west)}, anchor=west}")
    

    Background: PGFPlots.jl in general

    To achieve much more with PGFPlots.jl, I recommend inspecting the LaTeX code generated by the package. You can then consult the many resources already available for pgfplots.

    println(PGFPlots.tikzCode(a))
    

    The first lines of the output will be:

    \begin{axis}[
      title = {(a)},
      title style={at={(current bounding box.north west)}, anchor=west}
    ]
    
    ...
    

    As you can see, the style argument we provided is simply pasted as options of the axis environment. If you find out how to alter your plots in the pgfplots backend, you can immediately apply this knowledge through the style argument.

    Many examples of great plots are given in the documentation of PGFPlots.jl