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.
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}
}
}

draw=none? (Haven't tried it in this context, but that's the usual TikZ override.) – cfr Sep 19 '16 at 12:58pgfplotswell. (I know a tiny bit about it from answering questions here, but no more than that.) – cfr Sep 20 '16 at 15:48