3

I've been using pgfplots for some plots. I prefer using relatively thick lines in my plots which I feel are better suited to the font I'm using in my figures, accomplished with something like line width=1pt in the options to \begin{axis}. However, I'm now in the process of adding a second y-axis to a plot. The pgfplots manual says that I should use set layers. However, when I add set layers, I lose the effect of changing the line width. Any ideas for how I can get the line width parameter to stick to the axis lines, ticks, plot line, and so on?

While hunting around, I stumbled upon Bug in TikZ? Line width on layers which seems related, but since I'm not really a TikZ or pgfplots expert, I'm not sure how to apply the conclusion in that Q&A.

Here's a simple example using a single axis and plot, which shows the problem I'd like to overcome:

\documentclass{minimal}

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}


\begin{document}

\begin{tikzpicture}

\pgfplotsset{set layers} % commenting this line makes line width work

\begin{axis}[
    xmin=0,
    xmax=4,
    line width=1pt,
    every tick/.style={black}
]

\addplot {x^2};

\end{axis}
\end{tikzpicture}

\end{document}

With set layers active (undesirable behaviour):

Using <code>set layers</code>

After commenting set layers (what I want to see, but while using set layers):

After commenting <code>set layers</code>

2

see if this helps:

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}


\begin{document}
\pgfplotsset{set layers=axis on top,
             axis line style={line width=1pt},
             every axis plot post/.append style={line width=1pt}
             }
    \begin{tikzpicture}
\begin{axis}[
    xmin=0, xmax=4,
            ]
\addplot {x^2};
\end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

2
  • Yes, that does help, thank you, I probably wouldn't have figured every axis plot post on my own. I also added tick style={black,line width=1pt} to the \pgfplotsset command, to get the ticks to match the example. I wonder why the line widths all have to be set separately, though... – Tyler Jan 5 '18 at 3:28
  • @Tyler, i focused only on width of lines (your question is about them). pgfplotset you can move to preamble and collect in it all common presets. widths of lines is deliberately determined separately. only on this way you can control them separately. – Zarko Jan 5 '18 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.