提问于:
浏览数:
2109
2 回答
0
<p>需要设置的东西挺多的,我建议你还是用其他工具画吧,matlab或者python都可以。</p><p>这里给你一个例子,各个参数的设置自行查询pgfplot和pgfmanual文档</p><p>注意使用最新的pgfplot包</p><pre class="brush:plain;toolbar:false">\documentclass[a4paper, 12pt]{article}
\usepackage{xcolor}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{intersections}
\pgfplotsset{/tikz/font={\footnotesize}, compat=1.17}
\usepackage{xeCJK}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
tick align=inside,
xlabel={$x$},
ylabel={$y$},
xtick distance=1,
ytick distance=2,
xmin=-0.5, xmax=2.5,
ymin=-5, ymax=9,
extra y ticks={0},
extra y tick style={
tick label style={
anchor=north east,
yshift=-.5*\pgfkeysvalueof{/pgfplots/major tick length},
}
},
xlabel style={
at={(xticklabel* cs:1)},
anchor=west,
},
ylabel style={
at={(yticklabel* cs:1)},
anchor=south,
}
]
\addplot[
cyan,
thick,
domain=0:2,
name path global=A,
]
{9 * x^2 - 16 * x + 4};
\path[name path global=B] (0, 0) -- (2, 0);
\addplot[fill opacity=0.5] fill between [of=A and B,
split,
every even segment/.style={cyan!50},
every odd segment/.style={orange!50},
];
\fill [fill=brown, name intersections={
of=A and B,
name=i,
}]
(i-1) circle (2pt) node[anchor=north east] {$c$}
(i-2) circle (2pt) node[anchor=north west] {$c$};
\node[anchor=west] at (0.1, 8.2) {$y = f(x) = 9x^2 - 16x + 4$};
\end{axis}
\end{tikzpicture}
\end{document}</pre><p><img src="/data/ueditor/php/upload/image/20200505/1588613546550655.png" title="1588613546550655.png" alt="Screenshot from 2020-05-05 01-30-48.png" style="max-width:650px"></p>
0
<p>可以用tkz-fct宏包结合gnuplot实现:</p><pre class="brush:plain;toolbar:false">\documentclass[12pt, border = 8pt, varwidth, convert]{standalone}
\usepackage{tkz-fct}
\usepackage{tkz-euclide}% 绘制线段命令(此处仅标注尺寸)
\begin{document} %在document环境中撰写文档
\begin{tikzpicture}[scale=2]
% 定义坐标区域
\tkzInit[xmin=0, xmax=2,xstep=1, ymin=-4, ymax=8,ystep=4]
% 设置坐标轴刻度
\tkzSetUpAxis[tickwd=0.5pt,ticka=2pt, tickb=0pt]
% 绘制坐标轴
\tkzAxeXY
% 绘制曲线
\tkzFct[name path global=A, thick,color=cyan, domain=0:2]{9*x**2-16*x+4}
\tkzFct[domain=0:2]{0}
% 定义路径
\path[name path global= B](0,0)--(2,0);
% % 求交点
\path[black,name intersections={of=A and B,by={[label=below left:$c$]C, [label=below right:$c$]C'}}];
\tkzDrawAreafg[between= a and b,color=cyan!50]
\tkzDrawAreafg[between= b and a,color=orange!50]
\tkzText[black](1.5, 8.5){$y = f(x) = 9x^2 - 16x + 4$}
\end{tikzpicture}
\end{document}</pre><p>结果为:</p><p><img src="/data/ueditor/php/upload/image/20200507/1588835006443761.png" title="1588835006443761.png" alt="main-1.png" style="max-width:650px"></p><p>注意需要安装gnuplot,详情请用texdoc tkz-fct查看其说明书。</p>
你的回答
请登录后回答
你的回答将会帮助更多人,请务必认真回答问题。