Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I was wondering if it's possible to add shadows to markers within pgfplots. I tried the circular drop shadow option (from TikZ) which unfortunately had no effect at all. I also read that one can define custom marker styles with \pgfdeclareplotmark but that's way beyond my PGF knowledge.

\documentclass{scrartcl}

\usepackage{pgfplots}
\usetikzlibrary{shadows}
\pgfplotsset{%
  mystyle/.style={red,mark=*,mark options={fill=white,circular drop shadow}}}

\begin{document}

\begin{tikzpicture}
  \begin{axis}
     \addplot[mystyle] {x^2 - x + 4};
  \end{axis}
\end{tikzpicture}

\end{document}

Am I missing the easy solution (disregarding that nothing about shadows is mentioned in the pgfplots manual) or do I have to get deeper into PGF?

share|improve this question
    
I wonder why you'd want to do this. The entire point of a plot it to present data in a clear way, and I don't see that shadows really contribute. –  Joseph Wright Dec 29 '11 at 22:30
    
I would assume that the shadows lib relies on high-level tikz paths. However, plot marks are drawn using the more efficient pgf basic layer. Perhaps this makes a difference... what happens if you try mark=ball (which is the only marker using high-level tikz paths)? –  Christian Feuersänger Dec 29 '11 at 22:38
    
@JosephWright I thought exactly the same... It's just that I only have a few points which are compared to a empirical formula und they look a little bit lost. –  Johannes Dec 29 '11 at 22:49
    
@ChristianFeuersänger Changing the marker type to ball doesn't have any effect... –  Johannes Dec 29 '11 at 22:50
1  
Ok. Seems as if adding shadows requires more insight (as you feared). One way to do it might be to declare a plot mark and use \draw[circular drop shadow] \pgfextra{ <lowlevel marker code as before>}; as marker path expression. This could work (I do not know). In any way, it seems to be more involved - perhaps even without an easy solution. –  Christian Feuersänger Dec 29 '11 at 23:02
add comment

1 Answer

up vote 2 down vote accepted

It seems like this works:

\documentclass{scrartcl}
\usepackage{pgfplots}
\usetikzlibrary{shadows}

\pgfdeclareplotmark{*)}
{%
\fill[drop shadow={draw=black,fill=black,opacity=.25,shadow xshift=2pt,shadow
yshift=-2pt}] (0,0) circle [radius=2pt];
}

\begin{document}

\begin{tikzpicture}
  \begin{axis}
     \addplot[red,mark=*)] {x^2 - x + 4};
  \end{axis}
\end{tikzpicture}

\end{document}

It seems that it is ok to use regular tikz code inside \pgfdeclareplotmark. It may be horribly wrong, though, and could break any number of other things, so please use it with caution.

share|improve this answer
    
Plot marks are drawn after the plotting path... I would hope that all is right. In my opinion, it is the only promising approach. –  Christian Feuersänger Dec 30 '11 at 9:21
    
Thanks to both of you. I wasn't aware of the fact that it's possible to use TikZ code inside the \pgfdeclareplotmark. Although I would recommend the solution from Christian: \pgfdeclareplotmark{mymark}{\draw[circular drop shadow={draw=black!50}] \pgfextra{\pgfpathcircle{\pgfpointorigin}{\pgfplotmarksize}};}. This leads to – at least for circular markers – much nicer shadows. It's also not perfect because the draw=black!50 just yields nice results for standard opacity. Setting opacity=0.5 requires the draw color to be set at black!25. Somehow logical but not very handy... –  Johannes Dec 30 '11 at 10:13
    
As I'm new to this site: is it usual to edit nearly perfect answers to accept them or shall I create a new one? –  Johannes Dec 30 '11 at 10:30
    
I see, the marks created with circular drop shadow will only show up correctly in adobe reader, not in other viewers. That's why they did not work for me. I tried the Christian's suggestion, but as I normally do not use adobe reader, they looked really bad. –  Jan Hlavacek Dec 30 '11 at 16:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.