\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}[
axis lines = left,
]
\addplot[
domain=0:10,
color=red
]{x^3 - 15*x^2 + 63*x + 165};
\coordinate (A) at (100,10);
\coordinate (B) at (600,50);
\draw (A) node[below] {a} node[scale=0.75] {$\bullet$};
\draw (B) node[below] {b} node[scale=0.75] {$\bullet$};
\end{axis}
\end{tikzpicture}
\end{figure}
LaTeX 初学者会喜欢复制随附的教科书图表以及点、箭头、标签和线条。我想说的是,我找解决方案的能力还不错,但我有轻微的强迫症,想完美地复制它。
答案1
欢迎来到 TeX.SE!!!
我猜你想复制第一张图片。如果是这样的话,最好的方法(IMHO)是使用普通的 Ti钾Z 并声明一些函数(曲线、其导数以及可能的切线方程)。
例如:
\documentclass[tikz,border=1.618mm]{standalone}
\tikzset
{
every node/.style={black},
declare function=
{
f(\x)=1/3*(\x-0.5)^3-2*(\x-0.5)^2+3*(\x-0.5)+1.5; % function
df(\x)=(\x-0.5)^2-4*(\x-0.5)+3; % derivative
t(\x,\xo)=df(\xo)*(\x-\xo)+f(\xo); % tangent at \xo
}
}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
% some points (x-coordinates)
\def\a{0.5}
\def\b{2.5}
\def\c{4.5}
\def\tp{4.2} % tangent point
%\draw (0,0) grid (5,4);
% area
\fill[red!30] (\a,0) node[below] {\strut$a$} -- (\a,{f(\a)}) --
plot[domain=\a:\b,samples=51] (\x,{f(\x)}) |- node[below] {\strut$b$} cycle;
% axis
\draw[-latex] (-0.5,0) -- (5,0) node[below] {\strut$x$};
\draw[-latex] (0,-0.5) -- (0,4) node[left] {$y$};
% tangent line
\draw (\tp-0.5,{t(\tp-0.5,\tp)}) -- (\tp+0.7,{t(\tp+0.7,\tp)}) coordinate[pos=0.2] (r);
% curve
\draw[red!70!black,thick] plot[domain=\a:\c,samples=101] (\x,{f(\x)});
% point P
\fill (\tp,{f(\tp)}) circle (0.5mm) node[left] {$P$};
% labels
\node at (1,3.2) {$y=f(x)$};
\draw[latex-] (2,2) to[out= 30,in=240] (3,3) node[above] {area = ?};
\draw[latex-] (r) to[out=-30,in=120] (4.5,1) node[below] {slope = ?};
\end{tikzpicture}
\end{document}
答案2
使用tzplot
:
\documentclass{standalone}
\usepackage{tzplot}
\begin{document}
\begin{tikzpicture}[yscale=.05]
%\tzhelplines[thick,ystep=1/.05](11,160)
%% axes
\tzaxes(-1,-20)(11,160){$x$}[b]{$y$}[l]
\tzticks{1,2,...,10}{20,40,...,140}
\tzshoworigin
%% f(x)
\def\Fx{(\x)^3-15*(\x)^2+63*\x+20}
\tzfn[thick]\Fx[0:10]
%% area
\tzvXpointat{Fx}{1.5}(A)
\tzvXpointat{Fx}{4.5}(B)
\tzprojx[dashed](A){$a$}
\tzprojx[dashed](B){$b$}
\tzfnarea*[red]\Fx[1.5:4.5] % area
%% tangent
\tzvXpointat*{Fx}{9}(P){$P$}[al]
\tztangent[red]{Fx}(P)[8:10.5]
%% labels
\tznode(1,120){$f(x)=x^3-15x^2+63x+20$}[r]
\tzto[<-,bend left=3](3,80)(5,100){area=?}[r]
\tzto[<-,bend left=1](8.5,80)(9,60){slope=?}[b]
\end{tikzpicture}
\end{document}