我想绘制这个图形,这是我迄今为止编写的代码,但形状看起来很不一样......我无法解决如何用点填充区域......请帮帮我。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{tikzpicture}[scale=1]
% Axis
\draw (0,7) -- (0,0) node[below]{0} -- (7,0) node[below] {1};
\draw (0,7) -- (7,7) -- (7,0);
% curve
\draw (0,0) to (7,7);
\draw [very thick] (0,0) to [out=90, in=180] (2,2);
\draw [very thick] (2,2) to [out=0, in=270] (4,4);
\draw [very thick] (4,4) to [out=90, in=180] (7,6);
\draw (0.3,0.3) to [out=0, in=-270] (0.5,0) ;
\node[right] at (0.6,0.25) {$45^{o}$};
\draw [dashed] (2,0) -- (2,2);
\draw [dashed] (4,0) -- (4,4);
\draw [dashed] (5.9,0) -- (5.9,5.9);
\node[below] at (2,0) {\large $\lambda_1$};
\node[below] at (4,0) {\large $\lambda_2$};
\node[below] at (5.9,0) {\large $\lambda_3$};
\draw[<-,>=latex] (2,6) node[above] {\LARGE \begin{tabular}{c}$D(e(\lambda)$)\end{tabular}} to[out=-90,in=-100] (4.05,4.4);
\node[above] at (1.9,6.5) {-};
\end{tikzpicture}
\end{figure}
\end{document}
答案1
正如 Henri 所说,您可以定义自己的图案。下面的代码显示了一个这样的定义。您可以使用 键更改点的大小dots size
,例如\fill [pattern=mydots, dots size=3pt]
,并使用 更改间距dots spread
,例如\fill [pattern=mydots, dots spread=15pt]
。
与 Jasper 一样,我使用\bar{e}
而不是手动绘制该条,而是使用arc
来绘制角度标记。我还使用循环来绘制带有 lambda 的三条虚线。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{patterns}
\tikzset{
dots size/.store in=\dotssize,
dots size=1pt,
dots spread/.store in=\dotsspread,
dots spread=10pt
}
\makeatletter
\pgfdeclarepatternformonly[\dotssize,\dotsspread]{mydots}
{\pgfpointorigin}
{\pgfpoint{\dotsspread}{\dotsspread}}
{\pgfpoint{\dotsspread}{\dotsspread}}
{
\pgfsetcolor{\tikz@pattern@color}
\pgfpathcircle{\pgfpoint{\dotsspread/2}{\dotsspread/2}}{\dotssize}
\pgfusepath{fill}
}
\makeatother
\begin{document}
\begin{tikzpicture}
% Axis
\draw (7,7) -| (0,0) node[below]{0} -| node[below] {1} cycle;
% curve
\draw (0,0) to (7,7);
\fill [pattern=mydots, opacity=0.7] (0,0) to [out=80,in=200] (2,2)
to [out=20, in=250] (4,4)
to [out=70, in=200] (7,6.4)
|- cycle;
\draw [very thick] (0,0) to [out=80,in=200] (2,2)
to [out=20, in=250] (4,4)
to [out=70, in=200] coordinate[pos=0.2] (m) (7,6.4);
\draw (0.5,0) arc[start angle=0,end angle=45,radius=0.5] node[midway,right] {$45^{\circ}$} ;
\foreach \i in {1,2,3}
\draw [dashed,thick] (2*\i,2*\i) -- (2*\i, 0) node[below,font=\large] {$\lambda_{\i}$};
\draw[<-,>=latex] (2,6) node[above] {\LARGE $D(\bar{e}(\lambda)$)} to[out=270,in=200] (m);
\end{tikzpicture}
\end{document}
计算交叉点
不确定这种情况是否有意义,但可以使用库来计算 D 曲线和直线之间的交点intersections
。不过这需要几秒钟。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{patterns, intersections}
\tikzset{
dots size/.store in=\dotssize,
dots size=1pt,
dots spread/.store in=\dotsspread,
dots spread=10pt
}
\makeatletter
\pgfdeclarepatternformonly[\dotssize,\dotsspread]{mydots}
{\pgfpointorigin}
{\pgfpoint{\dotsspread}{\dotsspread}}
{\pgfpoint{\dotsspread}{\dotsspread}}
{
\pgfsetcolor{\tikz@pattern@color}
\pgfpathcircle{\pgfpoint{\dotsspread/2}{\dotsspread/2}}{\dotssize}
\pgfusepath{fill}
}
\makeatother
\begin{document}
\begin{tikzpicture}
% Axis
\draw (7,7) -| (0,0) node[below]{0} -| node[below] {1} cycle;
% curve
% add name path=x
\draw [name path=x] (0,0) to (7,7);
\fill [pattern=mydots, opacity=0.7] (0,0) to [out=80,in=200] (2,2)
to [out=20, in=250] (4,4)
to [out=70, in=200] (7,6.4)
|- cycle;
% add name path=D
\draw [very thick, name path=D] (0,0) to [out=80,in=200] (2,2)
to [out=20, in=250] (4,4)
to [out=70, in=200] coordinate[pos=0.2] (m) (7,6.4);
\draw (0.5,0) arc[start angle=0,end angle=45,radius=0.5] node[midway,right] {$45^{\circ}$} ;
% find intersections
\path [name intersections={of=x and D, name=lambda}];
%first intersection is at x=0, so use intersections 2-4
\foreach [count=\i] \j in {2,3,4}
\draw [dashed,thick] (lambda-\j) -- (lambda-\j |- 0,0) node[below,font=\large] {$\lambda_{\i}$};
\draw[<-,>=latex] (2,6) node[above] {\LARGE $D(\bar{e}(\lambda)$)} to[out=270,in=200] (m);
\end{tikzpicture}
\end{document}
答案2
与亨利的答案非常相似,但有几个小的改进:
- 点状图案的阴影较浅
- 45°标记使用
arc
- 使用标签
\bar{}
- 轴和标签后面的曲线和图案
-
\documentclass[tikz]{standalone}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
% curve
\fill[pattern=dots,pattern color=black!25] (0,0) to[out=80, in=200] (2,2)
to[out=20, in=260] (4,4)
to[out=80, in=180, distance=45] (7,6)
-- (7,0) -- cycle;
\draw[very thick] (0,0) to[out=80, in=200] (2,2)
to[out=20, in=260] (4,4)
to[out=80, in=180, distance=45] (7,6);
\draw[<-,>=latex] (2,6) node[above] {\LARGE $D(\bar{e}(\lambda))$} to[out=-90,in=180] (4.05,4.4);
% axis
\draw (0,7) -- (0,0) node[below]{0} -- (7,0) node[below] {1}
-- (7,7) -- cycle;
\draw (0,0) to (7,7);
\draw (0:.5) arc (0:45:.5) node[above right,midway] {$45^{\circ}$};
\draw[dashed] (2,0) node[below] {\large $\lambda_1$} -- (2,2);
\draw[dashed] (4,0) node[below] {\large $\lambda_2$} -- (4,4);
\draw[dashed] (5.9,0) node[below] {\large $\lambda_3$} -- (5.9,5.9);
\end{tikzpicture}
\end{document}
答案3
您快完成了。我本来可以使用一些不同的角度。为了获得点画效果,我使用了图书馆dots
中的图案patterns
。
不幸的是 Ti 中的图案钾Z 没有任何参数,因此您必须忍受非常密集的填充。否则,您必须定义自己的点图案。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{figure}
\begin{tikzpicture}[scale=1]
% Axis
\draw (0,7) -- (0,0) node[below]{0} -- (7,0) node[below] {1};
\draw (0,7) -- (7,7) -- (7,0);
% curve
\draw (0,0) to (7,7);
\draw [very thick] (0,0) to [out=90, in=200] (2,2)
to [out=20, in=250] (4,4)
to [out=70, in=180] (7,6);
\fill [pattern=dots] (0,0) to [out=90, in=200] (2,2)
to [out=20, in=250] (4,4)
to [out=70, in=180] (7,6)
-- (7,0) -- cycle;
\draw (0.3,0.3) to [out=0, in=-270] (0.5,0) ;
\node[right] at (0.6,0.25) {$45^{o}$};
\draw [dashed] (2,0) -- (2,2);
\draw [dashed] (4,0) -- (4,4);
\draw [dashed] (5.9,0) -- (5.9,5.9);
\node[below] at (2,0) {\large $\lambda_1$};
\node[below] at (4,0) {\large $\lambda_2$};
\node[below] at (5.9,0) {\large $\lambda_3$};
\draw[<-,>=latex] (2,6) node[above] {\LARGE \begin{tabular}{c}$D(e(\lambda)$)\end{tabular}} to[out=-90,in=-100] (4.05,4.4);
\node[above] at (1.9,6.5) {-};
\end{tikzpicture}
\end{figure}
\end{document}
答案4
只是为了和 MetaFun 一起玩(双关语)。
\startMPpage
input hatching ;
numeric u, t, l[] ;
u := 6cm ;
l1 := .22u ;
l2 := .55u ;
l3 := .9u ;
t := .8 ;
draw unitsquare scaled (1u) ;
for i = 0, 1:
label.bot("$" & decimal i & "$", (i*u,0)) ;
endfor ;
draw (0,0) -- (1u,1u) ;
path p ; p := (0,0){up}
.. tension t .. (l1,l1)
.. tension t .. (l2,l2)
.. tension t .. (l3,l3)
.. tension t .. (1u,.92u);
draw image (
interim linecap := butt ;
draw p withpen pencircle scaled (2pt) ;
) ;
hatchoptions (dashed withdots);
hatchfill (p -- (1u,0) -- cycle) withcolor (
-45, % hatching angle
5pt, % distance between lines
-1pt % thickness of lines
);
for i = 1 upto 3:
draw (l[i],0) -- (l[i],l[i]) dashed evenly ;
label.bot("$\lambda_{" & decimal i & "}$", (l[i],0)) ;
endfor;
draw anglebetween(origin -- (1u,0),origin -- (l1,l1),"$45^\circ$") ;
label.top("$D(\bar{e}(\lambda))$", (.3u,.85u));
drawarrow (point 2.1 of p){left} .. {up}(.3u,.85u) ;
\stopMPpage