1

I have the following code, which produces the image below it.

\documentclass[preview]{standalone}

\usepackage{tikz-cd}
\usepackage{pgfplots}

\begin{document}

\begin{figure}[htp]
\centering
\begin{tikzpicture}[scale=1]
\begin{axis}[
    xmin=0, xmax=1,
    ymin=0, ymax=1,
    axis lines=center,
    axis on top=true,
    axis y line=none,
    domain=0:1]
    \addplot[only marks] 
table {
0.2 0.8
0.8 0.2
};
\addplot[only marks, mark=*,mark options={red}] 
table {
0.2 0.2
0.8 0.8
};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

enter image description here

This is working exactly as I want.

But now I want to add a mark right in the middle split between the two colors, half red and half black, more or less like this.

enter image description here

I tried improvising a combination of two halfcircle* options on pgfplots, one red and one black, but they have a white fill, plus an undesired border. This post, from its description, appeared to do something similar to what I want, but for some reason I could not make it work.

1 Answer 1

1

If I got your goal correctly, a (not too general) approach would be to draw the marker border in white to "hide" it, set the marker colour to black and use the fill=red marker option to customise the halfcircle* marker as you wish. Then you need to rotate it accordingly to your figure needs. Here a proof of concept.

\documentclass[border=3mm, tikz]{standalone}

\usepackage{tikz-cd}
\usepackage{pgfplots}

\tikzset{
    rotated halfcircle/.style={%
        mark=halfcircle*,
        mark color=black,
        fill=red,
        every mark/.append style={rotate=#1}
    }
}

\begin{document}
    \begin{tikzpicture}[scale=1, every mark/.append style={draw=white}]
        \begin{axis}[
            xmin=0, xmax=1,
            ymin=0, ymax=1,
            axis lines=center,
            axis on top=true,
            axis y line=none,
            domain=0:1
            ]
            \addplot[only marks]
            table {
                0.2 0.8
                0.8 0.2
            };
            \addplot[only marks, draw=white, fill=red]
            table {
                0.2 0.2
                0.8 0.8
            };
            \addplot[only marks, rotated halfcircle=90] 
            table {
                0.5 0.2
            };
            \addplot[only marks, rotated halfcircle=0]
            table {
                0.8 0.5
            };
            \addplot[only marks, rotated halfcircle=270] 
            table {
                0.5 0.8
            };
            \addplot[only marks, rotated halfcircle=180]
            table {
                0.2 0.5
            };
        \end{axis}
    \end{tikzpicture}
\end{document}

Of course, I then applied draw=white option to all markers to make them of the same size. You can scale them up, if you wish, adding e.g. mark size=4pt after draw=white in the tikzpicture optional argument.

sample

1
  • Beautiful, exactly what I wanted, thank you! Jul 19 at 9:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .