4

While trying to create a plot with pgfplots, I noticed that the output created by ghostscript with

gs -o main_opt.pdf -sDEVICE=pdfwrite main.pdf

to optimize the PDF (size is reduced to ~50%) is different from the original PDF. In the legend, the border of the plot marks is reset from solid to the respective line style.

broken plot marks

My investigations hinted me towards problems with transparency and postscript. Unfortunately, I think that transparency is necessary within the axis line on top style to avoid the double-drawing of the axis, ticks and ticklabels.

What might be the exact problem here? Why do the plot marks break, when I append transparent to the tick style (see MWE, below)?

Is there maybe some other solution without transparency like a "dontdraw"/"draw" switch, similar to "transparent"/"opaque"?


The following example does not contain the axis line on top style but does reproduce the problem:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.13}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    tick style=transparent,
    legend entries={1,2,3,4},
    xmin=0,xmax=1,ymin=0,ymax=1
    ]

    \addplot+[thick,solid,             mark options=solid,mark=*] coordinates {(0,0) (0.5,0.2) (1,1)};
    \addplot+[thick,densely dashed,    mark options=solid,mark=square*] coordinates {(0,0) (0.5,0.4) (1,1)};
    \addplot+[thick,densely dotted,    mark options=solid,mark=triangle*] coordinates {(0,0) (0.5,0.6) (1,1)};
    \addplot+[thick,densely dashdotted,mark options=solid,mark=diamond*] coordinates {(0,0) (0.5,0.8) (1,1)};

  \end{axis}
\end{tikzpicture}

\end{document}

UPDATE: Thanks to @cfr, I could rewrite the axis line on top style to fit my needs. I disabled the handling of ticklabel style because I don't need need it and reenabling this with ticklabel style=draw would actually draw the boxes around them.

\makeatletter \newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis} \makeatother
\pgfplotsset{axis line on top/.style={
    %% before
    %axis line style=transparent,
    %ticklabel style=transparent,
    %tick style=transparent,
    %% now
    axis line style={draw=none},
    tick style={draw=none},
    axis on top=false,

    after end axis/.append code={
      \pgfplotsset{
        %% before
        %axis line style=opaque,
        %ticklabel style=opaque,
        %tick style=opaque,
        %% now
        axis line style=draw,
        tick style=draw,

        grid=none}
      \pgfplotsdrawaxis}
  }
}
Stefan
  • 865
  • You mean like draw=none? (Haven't tried it in this context, but that's the usual TikZ override.) – cfr Sep 19 '16 at 12:58
  • @cfr I was obviously missing the obvious... Still, I don't know why it doesn't work as expected. – Stefan Sep 19 '16 at 13:27
  • But it still doesn't work? – cfr Sep 19 '16 at 14:46
  • @cfr It works with the added style. The question is: why didn't it work? The transparency of ticks or axis lines should be unrelated to the style of marks! I guess this is a question for Christian Feuersänger... – Stefan Sep 20 '16 at 05:13
  • Ideally yes. Or somebody who knows pgfplots well. (I know a tiny bit about it from answering questions here, but no more than that.) – cfr Sep 20 '16 at 15:48
  • 4
    I'm voting to close this question as off-topic because it is related to (problematic) optimization of external script (Ghostscript and ImageMagick) – Symbol 1 Mar 21 '17 at 20:17

0 Answers0