1

In the plot below, I need to have transparent markers without the line passing through them. For instance, the triangles are transparent but have a line inside, while the circles are white but not transparent, so when they overlap with other markers I can't see the ones behind (e.g., the 4th red circle covers the blue + behind it). How can I do this? I tried playing with fill and opacity, but none seems to work.

Here is the MWE source code

\documentclass{standalone}

\usepackage{tikz, pgfplots}
\pgfplotsset{compat = newest}

\begin{document}


\begin{tikzpicture}


\begin{axis}[%
ymin = -430,
ymax = -120,
line width = 1.5pt,
mark size = 4pt,
mark repeat = {2},
]

\addplot [color=blue, mark=+, mark size=6pt, mark options={solid, blue}]
table[row sep=crcr]{%
1   -472.957480807357\\
25  -407.963189641911\\
50  -348.341258904901\\
75  -300.95497457745\\
100 -258.298880770257\\
125 -243.890778388889\\
150 -226.421548850128\\
175 -215.832112386973\\
200 -208.517635426508\\
225 -199.096498330167\\
250 -189.692967894992\\
275 -186.753526449191\\
300 -183.497159414706\\
};


\addplot [color=blue, mark=triangle, mark options={solid, blue, fill=white}]
table[row sep=crcr]{%
1   -473.176111750593\\
25  -397.39812645437\\
50  -354.929271612088\\
75  -295.09171831629\\
100 -249.262040196353\\
125 -218.243641560284\\
150 -197.947382605722\\
175 -189.906388849135\\
200 -180.230493968517\\
225 -176.304549666994\\
250 -175.748222868004\\
275 -173.241346781042\\
300 -171.599255498579\\
};


\addplot [color=blue, mark=*, mark options={solid, blue, fill=white}]
table[row sep=crcr]{%
1   -472.957480807357\\
25  -378.795179413002\\
50  -304.921612885841\\
75  -256.604962585425\\
100 -214.004226470603\\
125 -200.756093258793\\
150 -178.52719562163\\
175 -171.100579318826\\
200 -168.623121164359\\
225 -162.97515948792\\
250 -159.712406558919\\
275 -158.41049116843\\
300 -154.723114522471\\
};


\addplot [color=blue, mark=x, mark size=6pt, mark options={solid, blue}]
table[row sep=crcr]{%
1   -473.176111750593\\
25  -390.474896185393\\
50  -291.096856168457\\
75  -230.010617278154\\
100 -191.261312838266\\
125 -180.306609644372\\
150 -178.845379658163\\
175 -175.00445053184\\
200 -169.001928454372\\
225 -158.091329556207\\
250 -157.357412473193\\
275 -151.358012141298\\
300 -147.389801314761\\
};


\addplot [color=red, mark=+, mark size=6pt, mark options={solid, red}]
table[row sep=crcr]{%
1   -472.957480807357\\
25  -414.946593981509\\
50  -359.981615335536\\
75  -298.093357705063\\
100 -259.317637521473\\
125 -234.620802887995\\
150 -219.964042527991\\
175 -193.897369886823\\
200 -187.112205665699\\
225 -185.340947104539\\
250 -183.150547448457\\
275 -175.778921819035\\
300 -174.648426114704\\
};


\addplot [color=red, mark=triangle, mark options={solid, red, fill=white, fill opacity=0}]
table[row sep=crcr]{%
1   -473.176111750593\\
25  -401.973519707451\\
50  -358.483658886226\\
75  -319.048621130437\\
100 -279.751537017567\\
125 -245.242260009398\\
150 -229.580752059355\\
175 -216.142874177003\\
200 -199.342475438751\\
225 -189.604601725526\\
250 -183.539205050181\\
275 -179.434918964193\\
300 -173.547274004663\\
};


\addplot [color=red, mark=*, mark options={solid, red, fill=white}]
table[row sep=crcr]{%
1   -472.501437134907\\
25  -372.559640943181\\
50  -308.209122258859\\
75  -273.406549290234\\
100 -238.771617912851\\
125 -229.104604465375\\
150 -221.052548304111\\
175 -213.010502464088\\
200 -199.973941023526\\
225 -197.974334957991\\
250 -198.191604035715\\
275 -196.993961931376\\
300 -196.945082195301\\
};


\addplot [color=red, mark=x, mark size=6pt, mark options={solid, red}]
table[row sep=crcr]{%
1   -473.176111750593\\
25  -389.032852432164\\
50  -309.929903134395\\
75  -245.478400959056\\
100 -227.0428164581\\
125 -206.155626802297\\
150 -204.108240939745\\
175 -195.316558439083\\
200 -192.070716289052\\
225 -188.600255620281\\
250 -186.914288571696\\
275 -185.942141280223\\
300 -187.401409980353\\
};


\end{axis}
\end{tikzpicture}%

\end{document}

MWE

2

I guess to make this happen in general, you need to make the plot marks nodes such that TikZ can use \pgfpointshapeborder (see p. 1031 of the pgfmanual) internally to stop the plot at the boundary. AFAIK this is not possible for plain plot marks. This answer comes thus with a new style spare node marks to which you can pass a plot mark shape. It (ab)uses show path construction to draw the segments. In its present form, it is limited to straight lines, but one can make it work for curves, too. In your code, I replaced

\addplot [color=red, mark=triangle, mark options={solid, red,fill=white, fill opacity=0}]

by

\addplot [color=red,spare node marks={regular polygon,regular polygon sides=3,inner sep=2pt}]

and the result is

enter image description here

As you can see, the blue line does not get wiped out inside the triangles, nor do the red plot lines run through the plot marks. The answer has also a spare marks style (my first attempt), which however suffers from the lack of suitable \pgfpointshapeborder coordinates.

Full MWE (I commented out the other red paths in order to avoid confusion):

\documentclass{standalone}

\usepackage{tikz, pgfplots}
\pgfplotsset{compat = newest}
\usetikzlibrary{decorations.pathreplacing, shapes.geometric}
\begin{document}
\tikzset{spare marks/.style={decorate,decoration={show path construction,
lineto code={\draw (\tikzinputsegmentfirst) node[inner sep=0pt] (aux0)
{\pgfuseplotmark{#1}}
(\tikzinputsegmentlast) node[inner sep=0pt] (aux1) {\pgfuseplotmark{#1}};
\draw (aux0) -- (aux1); }}},
spare node marks/.style={decorate,decoration={show path construction,
lineto code={\draw (\tikzinputsegmentfirst) node[inner sep=0pt,draw,#1] (aux0)
{} (\tikzinputsegmentlast) node[inner sep=0pt,draw,#1] (aux1) {};
\draw (aux0) -- (aux1); }}}
}

\begin{tikzpicture}[]


\begin{axis}[%
ymin = -430,
ymax = -120,
line width = 1.5pt,
mark size = 4pt,
mark repeat = {2},
]

\addplot [color=blue, mark=+, mark size=6pt, mark options={solid, blue}]
table[row sep=crcr]{%
1   -472.957480807357\\
25  -407.963189641911\\
50  -348.341258904901\\
75  -300.95497457745\\
100 -258.298880770257\\
125 -243.890778388889\\
150 -226.421548850128\\
175 -215.832112386973\\
200 -208.517635426508\\
225 -199.096498330167\\
250 -189.692967894992\\
275 -186.753526449191\\
300 -183.497159414706\\
};


\addplot [color=blue, mark=triangle, mark options={solid, blue, fill=white}]
table[row sep=crcr]{%
1   -473.176111750593\\
25  -397.39812645437\\
50  -354.929271612088\\
75  -295.09171831629\\
100 -249.262040196353\\
125 -218.243641560284\\
150 -197.947382605722\\
175 -189.906388849135\\
200 -180.230493968517\\
225 -176.304549666994\\
250 -175.748222868004\\
275 -173.241346781042\\
300 -171.599255498579\\
};


\addplot [color=blue, mark=*, mark options={solid, blue, fill=white}]
table[row sep=crcr]{%
1   -472.957480807357\\
25  -378.795179413002\\
50  -304.921612885841\\
75  -256.604962585425\\
100 -214.004226470603\\
125 -200.756093258793\\
150 -178.52719562163\\
175 -171.100579318826\\
200 -168.623121164359\\
225 -162.97515948792\\
250 -159.712406558919\\
275 -158.41049116843\\
300 -154.723114522471\\
};


\addplot [color=blue, mark=x, mark size=6pt, mark options={solid, blue}]
table[row sep=crcr]{%
1   -473.176111750593\\
25  -390.474896185393\\
50  -291.096856168457\\
75  -230.010617278154\\
100 -191.261312838266\\
125 -180.306609644372\\
150 -178.845379658163\\
175 -175.00445053184\\
200 -169.001928454372\\
225 -158.091329556207\\
250 -157.357412473193\\
275 -151.358012141298\\
300 -147.389801314761\\
};


% \addplot [color=red, mark=+, mark size=6pt, mark options={solid, red}]
% table[row sep=crcr]{%
% 1   -472.957480807357\\
% 25  -414.946593981509\\
% 50  -359.981615335536\\
% 75  -298.093357705063\\
% 100 -259.317637521473\\
% 125 -234.620802887995\\
% 150 -219.964042527991\\
% 175 -193.897369886823\\
% 200 -187.112205665699\\
% 225 -185.340947104539\\
% 250 -183.150547448457\\
% 275 -175.778921819035\\
% 300 -174.648426114704\\
% };
% 

%\addplot [color=red, mark=triangle, mark options={solid, red, fill=white, fill opacity=0}]
\addplot [color=red,spare node marks={regular polygon,regular polygon
sides=3,inner sep=2pt}]
table[row sep=crcr]{%
1   -473.176111750593\\
25  -401.973519707451\\
50  -358.483658886226\\
75  -319.048621130437\\
100 -279.751537017567\\
125 -245.242260009398\\
150 -229.580752059355\\
175 -216.142874177003\\
200 -199.342475438751\\
225 -189.604601725526\\
250 -183.539205050181\\
275 -179.434918964193\\
300 -173.547274004663\\
};


% \addplot [color=red, mark=*, mark options={solid, red, fill=white}]
% table[row sep=crcr]{%
% 1   -472.501437134907\\
% 25  -372.559640943181\\
% 50  -308.209122258859\\
% 75  -273.406549290234\\
% 100 -238.771617912851\\
% 125 -229.104604465375\\
% 150 -221.052548304111\\
% 175 -213.010502464088\\
% 200 -199.973941023526\\
% 225 -197.974334957991\\
% 250 -198.191604035715\\
% 275 -196.993961931376\\
% 300 -196.945082195301\\
% };
% 
% 
% \addplot [color=red, mark=x, mark size=6pt, mark options={solid, red}]
% table[row sep=crcr]{%
% 1   -473.176111750593\\
% 25  -389.032852432164\\
% 50  -309.929903134395\\
% 75  -245.478400959056\\
% 100 -227.0428164581\\
% 125 -206.155626802297\\
% 150 -204.108240939745\\
% 175 -195.316558439083\\
% 200 -192.070716289052\\
% 225 -188.600255620281\\
% 250 -186.914288571696\\
% 275 -185.942141280223\\
% 300 -187.401409980353\\
% };


\end{axis}
\end{tikzpicture}%

\end{document}
  • @Simon You're welcome. I can be simplified, depending on your real life requirements, and extended to curves and closed paths (see p. 583 where curveto code and lineto code are explained), and one may add a counter such that each node is drawn once etc. Please let me know if you have any such "feature requests". – marmot Dec 22 '18 at 23:36

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.