着色 Tikz 图片布局

着色 Tikz 图片布局

我正在尝试绘制函数并在它们之间进行阴影处理。代码如下:

\documentclass[a4paper, 12pt]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepgfplotslibrary{fillbetween}
% I included the formatting stuff as well
\usepackage{fancyhdr}
\usepackage[a4paper, portrait, margin=1in]{geometry}

\pagestyle{fancy}
\fancyhf{}
\rhead{October 18, 2018}
\lhead{Tutoring Notes}
\rfoot{\thepage}

\begin{document}

\begin{figure}[ht]

\centering

\begin{tikzpicture}[scale=1.75,line width=1pt]
\begin{axis}[
color= gray,
xmin=-4.9, 
xmax=4.9, 
ymin=-1.9, 
ymax=2.9, 
axis equal image, 
axis lines=middle, 
font=\scriptsize,
xtick distance=1,
ytick distance=1,
xticklabels={}, 
yticklabels={},
legend pos=outer north east,
inner axis line style={stealth-stealth}
]

\addplot[red, smooth, domain=-4.9:4.9, name path=1] {(8)/(4 + x^2)}; 
\addlegendentry[black]{$f(x)$}

\addplot[blue, smooth, domain=-4.9:4.9, name path=2]{(-16*x)/((4+x^2)^2)};
\addlegendentry[black]{$f'(x)$}

\addplot[green, smooth, domain=-4.9:4.9, name path=3]{-(((16)*((4 + 
x^2)^2))-((4 + x^2)*(64*(x^2))))/((4+x^2)^4)};
\addlegendentry[black]{$f''(x)$}

%\addplot[red, fill opacity=0.20] fill between [of=1 and 2,soft clip= 
{domain=2:4}];

\draw[black] (0,1) circle [radius=1];


\end{axis}
\end{tikzpicture}

\caption{Plotting the curve when $r=1$.}
\label{fig:1}

\end{figure}

\end{document}

当注释掉这一行时,我会在所需的位置得到一个图表(这是更大文档的一部分):

位置好

但是,当我取消注释用于在两条曲线之间的区域上着色的绘图命令时,文档中出现了一个巨大的跳跃,图例也消失了:

位置不好

为什么会发生这种情况?当我绘制其他函数时也会发生这种情况,但我不知道为什么。

答案1

我真的不知道发生了什么。很可能与这些问题,其中fillbetween也移动了一些坐标。将你的图编译为独立图后,你会发现你的图例被移到了月球上,这是你在使用 A4 纸时无法体会到的。这实际上移动了图(并使图例消失)。它建议采用以下解决方法,将图例移动到更有意义的位置。

\documentclass[a4paper, 12pt]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepgfplotslibrary{fillbetween}
% I included the formatting stuff as well
\usepackage{fancyhdr}
\usepackage[a4paper, portrait, margin=1in]{geometry}

\pagestyle{fancy}
\fancyhf{}
\rhead{October 18, 2018}
\lhead{Tutoring Notes}
\rfoot{\thepage}

\begin{document}

\begin{figure}[ht]

\centering

\begin{tikzpicture}[scale=1.75,line width=1pt]
\begin{axis}[
color= gray,
xmin=-4.9, 
xmax=4.9, 
ymin=-1.9, 
ymax=2.9, 
axis equal image, 
axis lines=middle, 
font=\scriptsize,
xtick distance=1,
ytick distance=1,
xticklabels={}, 
yticklabels={},
%legend pos=outer north east,
legend to name=named,
inner axis line style={stealth-stealth}
]
\addplot[red, smooth, domain=-4.9:4.9, name path=1] {(8)/(4 + x^2)}; 
\addlegendentry[black]{$f(x)$}

\addplot[blue, smooth, domain=-4.9:4.9, name path=2]{(-16*x)/((4+x^2)^2)};
\addlegendentry[black]{$f'(x)$}

\addplot[green, smooth, domain=-4.9:4.9, name path=3]{-(((16)*((4 + 
x^2)^2))-((4 + x^2)*(64*(x^2))))/((4+x^2)^4)};
\addlegendentry[black]{$f''(x)$}

\addplot[red, fill opacity=0.20] fill between [of=2 and 1,soft clip= 
{domain=2:4}];

\draw[black] (0,1) circle [radius=1];

\end{axis}
\node at (current axis.north east) {\ref{named}};
\end{tikzpicture}

\caption{Plotting the curve when $r=1$.}
\label{fig:1}

\end{figure}
\end{document}

在此处输入图片描述

当然,真正解决这个问题是更理想的。我猜除了 pgfplots 的作者 Christian Feuersänger 之外,可能没有多少人能提供答案。

相关内容