第一个有效,而第二个无效。我认为问题出在第二个轴中只有负值(其余完全相等)。有人能帮帮我吗?
以下是代码:
\begin{figure}
\begin{tikzpicture}[scale=0.7]
\begin{axis}[
axis lines = center,
xlabel = {$x$},
ylabel = {$y$},
height=10cm, width=10cm, grid=major,grid style={dashed, gray!30},
xmin=-6, xmax=6, ymin=-1, ymax=100
]%,xtick={1,...,10},ytick={50,100,...,200}]
\addplot[draw=blue,domain=-9:9]{3*2^x};
\end{axis}
\end{tikzpicture}
\caption{$f(x)=3 \cdot 2^x$}
\end{figure}
\begin{figure}
\begin{tikzpicture}[scale=0.7]
\begin{axis}[
axis lines = center,
xlabel = {$x$},
ylabel = {$y$},
height=10cm, width=10cm, grid=major,grid style={dashed, gray!30},
xmin=-6, xmax=6, ymin=**-100**, ymax=**1**
]%,xtick={1,...,10},ytick={50,100,...,200}]
\addplot[draw=blue,domain=-9:9]{-3*(1/2)^x};
\end{axis}
\end{tikzpicture}
\caption{$f(x)=(-3) \cdot \big( \frac{1}{2} \big)^x$}
\end{figure}
答案1
问题在于这个数字非常高,正如周围的框架所显示的那样:
\begin{figure}
\fbox{
\begin{tikzpicture}[scale=0.7]
\begin{axis}[
axis lines = center,
xlabel = {$x$},
ylabel = {$y$},
height=10cm, width=10cm, grid=major,grid style={dashed, gray!30},
xmin=-6, xmax=6, ymin=-100, ymax=0
]%,xtick={1,...,10},ytick={50,100,...,200}]
\addplot[draw=blue,domain=-9:9]{-3*(1/2)^x};
\end{axis}
\end{tikzpicture}
}
\caption{$f(x)=(-3) \cdot \big( \frac{1}{2} \big)^x$}
\end{figure}
其结果为:
问题显然出在域 上-9:9
。 值x=-9
对 产生了一个非常大的负值y
,这导致了错误的边界框。 这可能是一个错误,但可以通过使用-6:6
域(与 重合xmin:xmax
)轻松规避:
\begin{figure}
\fbox{
\begin{tikzpicture}[scale=0.7]
\begin{axis}[
axis lines = center,
xlabel = {$x$},
ylabel = {$y$},
height=10cm, width=10cm, grid=major,grid style={dashed, gray!30},
xmin=-6, xmax=6, ymin=-100, ymax=0
]%,xtick={1,...,10},ytick={50,100,...,200}]
\addplot[draw=blue,domain=-6:6]{-3*(1/2)^x};
\end{axis}
\end{tikzpicture}
}
\caption{$f(x)=(-3) \cdot \big( \frac{1}{2} \big)^x$}
\end{figure}