我觉得补充一下很有用
\pgfplotsset{/tikz/every picture/.append style={trim axis left,trim axis right}}
在我的前言中提到了边界框限制。但是当我使用该legend to name
功能时(见附件),我收到以下错误:
! Package pgf Error: No shape named current axis is known
我怎样才能解决这个问题?
梅威瑟:
\documentclass{article}
\usepackage{lipsum,pgfplots}
\pgfplotsset{compat=1.7}
\usepgfplotslibrary{external}
\usetikzlibrary{pgfplots.external}
\tikzexternalize[shell escape=-enable-write18]
\pgfplotsset{/tikz/every picture/.append style={trim axis left,trim axis right}}
\begin{document}
\setlength\fboxsep{0pt}
\begin{figure}[h!]\centering
\fbox{\begin{tikzpicture}
\begin{axis}[domain=-2:2,
width=0.5\textwidth,
xlabel={$x$},ylabel={$y$},
%
legend to name=mylegend,
legend columns=-1,
legend entries={$x^2$,$x^3$}]
\addplot {x^2};\addplot {x^3};
\end{axis}
\end{tikzpicture}}%
%
\hspace{1.5cm}%
%
\fbox{\begin{tikzpicture}
\begin{axis}[domain=-2:2,
width=0.5\textwidth,
xlabel={$x$},ylabel={$y$}]
\addplot {x^2};\addplot {x^3};
\end{axis}
\end{tikzpicture}}%
\tikzexternaldisable\ref{mylegend}\tikzexternalenable
% http://tex.stackexchange.com/q/37471/14497
\end{figure}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis.
\end{document}
答案1
every picture
事实证明,一个出乎意料的简单解决方案是重新定义风格
\pgfplotsset{/tikz/every picture/.style={}}
致电之前\ref
。关于我的 MWE:
{\pgfplotsset{/tikz/every picture/.style={}}
\tikzexternaldisable\ref{mylegend}\tikzexternalenable
}
成功了。