Discussion:
pgf (pgfplots): half-filled circle as plot marker
(too old to reply)
Joseph Wright
2009-10-23 13:46:27 UTC
Permalink
Hello all,

I'm doing some graphs in pgfplots, and would like to use half-filled
circles as plot markers. Fully filled with black or white is easy:

\addplot[color = black, fill = white, mark = *]
\addplot[color = black, fill = black, mark = *]

but I'm not sure how to fill half of the circle black. I've taken a
look at the code, but as far as I can tell it only works easily for
fully-filled circles. Anyone tried this sort of thing? (I'm hoping to
be able to fill either the top, bottom, left or right halves black,
giving me 6 symbols in total.)
--
Joseph Wright
T3X
2009-10-23 16:06:16 UTC
Permalink
Post by Joseph Wright
Hello all,
I'm doing some graphs in pgfplots, and would like to use half-filled
\addplot[color = black,  fill = white,  mark = *]
\addplot[color = black,  fill = black,  mark = *]
but I'm not sure how to fill half of the circle black. I've taken a
look at the code, but as far as I can tell it only works easily for
fully-filled circles. Anyone tried this sort of thing? (I'm hoping to
be able to fill either the top, bottom, left or right halves black,
giving me 6 symbols in total.)
Does this fit the bill?

\pgfdeclareplotmark{halfcircle}{%
\pgfpathcircle{\pgfpoint{0pt}{0pt}}{\pgfplotmarksize}
\pgfusepathqstroke
\pgfpathmoveto{\pgfpoint{\pgfplotmarksize}{0pt}}
\pgfpatharc{0}{180}{\pgfplotmarksize}
\pgfpathclose
\pgfusepathqfill
}

Other combinations you get by rotating it, e.g.:

\addplot[color=black,  mark=halfcicle, mark options={rotate=90}] ...

Cheers,

Tomek
Joseph Wright
2009-10-23 16:19:53 UTC
Permalink
Post by T3X
Does this fit the bill?
\pgfdeclareplotmark{halfcircle}{%
\pgfpathcircle{\pgfpoint{0pt}{0pt}}{\pgfplotmarksize}
\pgfusepathqstroke
\pgfpathmoveto{\pgfpoint{\pgfplotmarksize}{0pt}}
\pgfpatharc{0}{180}{\pgfplotmarksize}
\pgfpathclose
\pgfusepathqfill
}
\addplot[color=black,  mark=halfcicle, mark options={rotate=90}] ...
Cheers,
Tomek
Hello Tomek,

Exactly what I wanted: thanks very much.
--
Joseph Wright
Joseph Wright
2009-12-15 09:26:28 UTC
Permalink
Post by Joseph Wright
Hello Tomek,
Exactly what I wanted: thanks very much.
--
Joseph Wright
I've noticed a small flaw: the background circle is not filled, so
things look odd if there is an overlap at the axis. I can fix that
with:

\pgfdeclareplotmark{halfcircle}{%
\pgfsetfillcolor{white}%
\pgfpathcircle{\pgfpoint{0pt}{0pt}}{\pgfplotmarksize}
\pgfusepathqfillstroke
\pgfsetfillcolor{black}%
\pgfpathmoveto{\pgfpoint{\pgfplotmarksize}{0pt}}
\pgfpatharc{0}{180}{\pgfplotmarksize}
\pgfpathclose
\pgfusepathqfill
}

which works, but I'd like to get a general solution. I accept I might
need to set the background (white) explicitly, but is there a way to
achieve the same effect without needing to fix the foreground fill? I
tried things like grouping the first part, etc., but without success.
--
Joseph Wright
Leo
2009-12-15 10:29:20 UTC
Permalink
I tried things like grouping the first part, etc., but without
success.
I have success with:

\pgfdeclareplotmark{halfcircle}{%
\begin{pgfscope}
\pgfpathcircle{\pgfpointorigin}{\pgfplotmarksize}
\pgfsetfillcolor{white}
\pgfusepathqfillstroke
\end{pgfscope}
\pgfpathmoveto{\pgfqpoint{0pt}{\pgfplotmarksize}}
\pgfpatharc{90}{270}{\pgfplotmarksize}
\pgfpathclose
\pgfusepathqfill
}

I am using the devel version of pgf and pgfplots.

Best,

Leo
Joseph Wright
2009-12-15 12:21:31 UTC
Permalink
Post by T3X
I tried things like grouping the first part, etc., but without
success.
\pgfdeclareplotmark{halfcircle}{%
  \begin{pgfscope}
    \pgfpathcircle{\pgfpointorigin}{\pgfplotmarksize}
    \pgfsetfillcolor{white}
    \pgfusepathqfillstroke
  \end{pgfscope}
  \pgfpathmoveto{\pgfqpoint{0pt}{\pgfplotmarksize}}
  \pgfpatharc{90}{270}{\pgfplotmarksize}
  \pgfpathclose
  \pgfusepathqfill
}
I am using the devel version of pgf and pgfplots.
Best,
Leo
Hello Leo,

Thanks for that: works perfectly for me.
--
Joseph Wright

Loading...