我需要制作一张看起来像
我看到了类似的问题这里--shell-escape
但是当我使用或 使用 时,红色函数线均未出现--enable-write18
。顺便说一下,我使用的是 TeXstudio。已安装 TikZ 和 pgf 包。
UPD:我使用的代码
\documentclass[]{scrartcl}
\usepackage{tkz-fct}
\begin{document}
\begin{tikzpicture}[scale=1.25]
\tkzInit[xmax=8,ymax=4]
\tkzAxeXY[ticks=false]
\tkzGrid
\tkzFct[color = red, domain =0.125:8]{4./x}
\tkzDrawRiemannSumInf[fill=green!60,
opacity=.2,
color=green,
line width=1pt,
interval=1:8,
number=7]
\foreach \x/\t in {1.5/$a_1$,2.5/$a_2$,3.5/$a_3$,7.5/$a_7$}
\node[green!50!black] at (\x,{4/(\x+1)-0.25}){\t};
\end{tikzpicture}
\end{document}
也许有一些好的图形编辑器可以手绘这样的东西?
答案1
您可以使用pgfplots
回答,它不依赖外部程序来计算函数:
\documentclass{article}
\usepackage{pgfplots}
% right hand sums
\pgfplotsset{
right segments/.code={\pgfmathsetmacro\rightsegments{#1}},
right segments=3,
right/.style args={#1:#2}{
ybar interval,
domain=#1+((#2-#1)/\rightsegments):#2+((#2-#1)/\rightsegments),
samples=\rightsegments+1,
x filter/.code=\pgfmathparse{\pgfmathresult-((#2-#1)/\rightsegments)}
}
}
\begin{document}
\begin{tikzpicture}[/pgf/declare function={f=4/x;}]
\begin{axis}[
xmin=0,xmax=8.5,ymin=0,ymax=4,
domain=0:8.5,
samples=100,
axis lines=left,
clip=false,
restrict y to domain=0:4
]
\addplot [thick, red] {f};
\addplot [
black!80,fill=green,opacity=.3,
right segments=7,
right=1:8,
] {f};
\draw [ultra thick, black!60, -latex] (axis cs:1.5,0) -- ++(0,-5ex) node [anchor=north, black] {thread 1};
\draw [ultra thick, black!60, -latex] (axis cs:2.5,0) -- ++(0,-8ex) node [anchor=north, black] {thread 2};
\draw [ultra thick, black!60, -latex] (axis cs:7.5,0) -- ++(0,-5ex) node [anchor=north, black] {thread n};
\end{axis}
\end{tikzpicture}
\end{document}