Is there a way to get for all tikz
-plots in one LaTeX document the same distance between the plot mark
s, ie the distance between the marks should be independent of sample size. It would be really great if this change wouldn't interfere with the legend like change the position of the marker in the legend
etc. Thanks.
Edit: Unfortunately the distance of all data points (not in the mini example but for the real data) is not the same therefore it would be nice if I could define distance between the marks in cm.
\documentclass[tikz,border=1mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{decorations.markings}
\pgfplotsset{compat=1.11}
%\tikzset{mark/.style={
% decoration={
% markings,
% mark= between positions 0 and 1 step 5mm with
% {
% %\node[circle,inner sep=2pt,fill=blue]{};
% },
% },
% postaction={decorate}
% }
%}
\begin{document}
\begin{tikzpicture}
\begin{axis}[]
\addplot[
blue,
domain=0:3,
samples=100,
mark=*
]
{exp(x)};
\addlegendentry{exp(x)};
\addplot[
red,
domain=0:3,
samples=20,
mark=diamond
]
{4*x};
\addlegendentry{4x};
\end{axis}
\end{tikzpicture}
\end{document}
edit: Is is possible to pass to tikz such options like mark size
or mark options={solid}
?
\addplot [color=black,loosely dotted,line width=1.5pt, mark=*,mark size=3pt, mark=diamond,mark options={solid}]
edit2: I found out how I can set the marks solid
in the legend but how can I do the same in for the plot? Any ideas how to get the plot marks solid
in the actual plot?
\tikzset{
nomorepostactions/.code={\let\tikz@postactions=\pgfutil@empty},
mymark/.style={decoration={markings,
mark= between positions 0 and 1 step (1/11)*\pgfdecoratedpathlength with{%
\pgfuseplotmark{#1},%
},
},
postaction={decorate},
/pgfplots/legend image post style={mark=#1,every path/.append style={nomorepostactions}},
},
every mark/.append style={solid,mark size=3},
}
Best Answer
Similar to Harish's answer but removes the need to plot twice. You basically need to stop the postaction reaching to the legend pictures because that is what is causing the funky mark placement. And that you can do with our good ol' answer to Applying a postaction to every path in TikZ
You can also add yet another parameter for how many marker you want to have by dividing the total path length to a fixed number. Here I went with 11. (replacing it with a distance is what you wish probably but I put here as an alternative)
with 1 cm mark distance
EDIT For the added style question, the code now gives