2

I have this code:

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{shadows}
\begin{document}
\begin{tikzpicture}
\node[drop shadow,draw,fill=green] {
  \begin{tikzpicture}
  \begin{axis}
   \addplot coordinates {(0,0) (1,1)};
  \end{axis}
  \end{tikzpicture}
};
\path [use as bounding box] (-5,-5) rectangle (5,5);
\end{tikzpicture}
\end{document}

which gives

enter image description here

The problem is now that the plot has also a drop shadow. How can I avoid this? I tried to use fill either in pre- or postaction or changing the pgfplot background to white but that dind't help.

  • Why are you including the tikzpicture with the plot inside the \node? Can you describe what you are trying to achieve? – Gonzalo Medina Feb 2 '14 at 17:48
  • I want to connect different nodes in a flow diagram. – Reza Feb 2 '14 at 18:14
2

The inner nodes will inherit the shadow; that's why is not, generally speaking, a good idea to nest tikzpicrures.

You can use a background layer to add the colored background:

\documentclass[tikz,border=5pt]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{shadows}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\begin{document}

\begin{tikzpicture}
  \begin{axis}
   \addplot coordinates {(0,0) (1,1)};
  \end{axis}
  \begin{pgfonlayer}{background}
  \draw[drop shadow,draw,fill=green] 
    ([yshift=3pt]current bounding box.north west) rectangle ([xshift=3pt]current bounding box.south east);
  \end{pgfonlayer}
\end{tikzpicture}

\end{document}

enter image description here

In a comment it has been requested to have two plots, each one with a colored background and a drop shadow and both connected with an arrow; this can be done by saving the plots in boxes (safe method for nesting tikzpictures) and then using nodes to place them and draw the arrow. An example:

enter image description here

\documentclass[tikz,border=5pt]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{positioning,shadows}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\newsavebox\myboxa
\newsavebox\myboxb

\savebox\myboxa{%
\begin{tikzpicture}
  \begin{axis}
   \addplot coordinates {(0,0) (1,1)};
  \end{axis}
  \begin{pgfonlayer}{background}
  \draw[drop shadow,draw,fill=green] 
    ([yshift=3pt]current bounding box.north west) rectangle ([xshift=3pt]current bounding box.south east);
  \end{pgfonlayer}
\end{tikzpicture}%
}
\savebox\myboxb{%
\begin{tikzpicture}
  \begin{axis}
   \addplot coordinates {(0,0) (0.4,0.6) (0.7,0.2) (1,1)};
  \end{axis}
  \begin{pgfonlayer}{background}
  \draw[drop shadow,draw,fill=green] 
    ([yshift=3pt]current bounding box.north west) rectangle ([xshift=3pt]current bounding box.south east);
  \end{pgfonlayer}
\end{tikzpicture}%
}

\begin{document}

\begin{tikzpicture}
\node (a) {\usebox\myboxa};
\node[right=of a] (b) {\usebox\myboxb};
\draw[->] (a) -- (b);
\end{tikzpicture}

\end{document}
  • thanks for your solution! What would be the correct way to connect 2 nodes with pgfplots inside, instead of nesting the pgfplots inside the nodes? – Reza Feb 2 '14 at 18:23
  • @Reza I am not sure what you are asking. Do you have two plots and you want to connect some points from one of them to some points of the other? – Gonzalo Medina Feb 2 '14 at 18:25
  • sorry for my bad explanation. I have two nodes with a pgfplot inside and I want just to have drop shadow on every node and connect them with an arrow: \draw[->] (node1) -- (node2); – Reza Feb 2 '14 at 18:28
  • @Reza Ah, now I see. Please see my updated answer. – Gonzalo Medina Feb 2 '14 at 19:05
  • cool thanks, exactly what I was looking for! Since which version is this possible? – Reza Feb 2 '14 at 19:14

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.