我有这个代码:
\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}
这使
现在的问题是绘图也有阴影。我该如何避免这种情况?我尝试使用fill
-pre
或postaction
将 pgfplot 背景更改为白色,但这没有帮助。
答案1
内部节点将继承阴影;这就是为什么嵌套不是一个好主意tikzpicrure
。
您可以使用背景层添加彩色背景:
\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}
在评论中,有人要求有两个图,每个图都有彩色背景和阴影,并且都用箭头连接;这可以通过将图保存在框中(嵌套的安全方法tikzpicture
)然后使用节点放置它们并绘制箭头来实现。一个例子:
\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}