我想要显示以下三个函数,其中常数A = [1,2,4]
A*x^2*(1-x)^2
我最初的 MWE
\documentclass[11pt, oneside,dvipsnames]{article}
\usepackage{amsmath, amsthm, amssymb, calrsfs, wasysym, verbatim, bbm, color, graphics, geometry, mathtools, cases, graphicx}
\usepackage[T1]{fontenc}
\usepackage{pgfplots,pgfplotstable,filecontents,pdflscape}
\begin{document}
\maketitle
\newpage
\tableofcontents
\pgfplotsset{compat=1.9}
\begin{tikzpicture}
\begin{axis}[
axis lines = left,
xlabel = $c$,
ylabel = {$f(c)$},
]
% A=1
\addplot [
domain=-0.1:1.1,
samples=500,
color=red,
]
{x^2 * (1-x)^2};
\addlegendentry{$c^2\,(1-c)^2$}
% A=2
\addplot [
domain=-0.1:1.1,
samples=500,
color=blue,
]
{2 * x^2 * (1-x)^2};
\addlegendentry{$2\,c^2\,(1-c)^2$}
% A=4
\addplot [
domain=-0.1:1.1,
samples=500,
color=blue,
]
{4 * x^2 *(1-x)^2};
\addlegendentry{$4\,c^2\,(1-c)^2$}
\end{axis}
\end{tikzpicture}
输出结果如下,
保持其余代码不变,我合并了帖子中回答的代码在 pgfplots 中缩放 Y 轴和 X 轴进入前面的主代码。
\usepackage{pgfplots,pgfplotstable,filecontents,pdflscape}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=15cm,
axis lines = middle, %% instead of above two lines this one is enough
scaled ticks=false,
axis equal,
grid=major,
ymax=1.2, ymin=0,
xmax=1.2, xmin=-0.2,
ytick={0,...,1.2},
xtick={-0.2,...,1.2},
xlabel = $c$,
ylabel = {$f(c)$},
]
.
.
.
结果是,
我希望 pgfplot 显示类似这样的输出,
我该怎么做?需要附加哪部分代码?
答案1
您应该删除 axis equal 选项。您可以使用 ymin/ymax 来缩小值。我还添加了largelimits 以将轴在每个方向上延长 1%。
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = middle, %% instead of above two lines this one is enough
scaled ticks=false,
% axis equal,
grid=both,
minor tick num = 1,
% xmin=-0.2,
% xmax=1.2,
ymin=-0.05, ymax=.4,
% restrict y to domain=-0.1:0.4,
enlargelimits=.01,
xlabel = $c$,
ylabel = {$f(c)$},
width=10cm,
height=5cm,
]
% A=1
\addplot [
domain=-0.1:1.1,
samples=500,
color=blue,
]
{x^2 * (1-x)^2};
\addlegendentry{$c^2\,(1-c)^2$}
% A=2
\addplot [
domain=-0.1:1.1,
samples=500,
color=green,
]
{2 * x^2 * (1-x)^2};
\addlegendentry{$2\,c^2\,(1-c)^2$}
% A=4
\addplot [
domain=-0.1:1.1,
samples=500,
color=orange,
]
{4 * x^2 *(1-x)^2};
\addlegendentry{$4\,c^2\,(1-c)^2$}
\end{axis}
\end{tikzpicture}
\end{document}