我想画这个
因此,我创建了这个代码
\documentclass[border=12pt]{standalone}
\usepackage{tikz,tkz-base,tkz-tab}
\usetikzlibrary{positioning}
\usepackage{pifont}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm]
\begin{axis}[scale=1.3, x=1cm, y=1cm, axis lines=middle, xmin=-3.5, xmax=7, ymin=-3, ymax=6, xtick={-3,...,6}, ytick={-2,...,5},]
\draw[line width=1pt, color=blue, smooth, samples=100, domain=0:6.5] plot(\x,{2 *\x * ln \x - 2*\x });
\draw[line width=1pt, color=blue, smooth, samples=100, domain=-2:6] plot({2 *\x * ln \x - 2*\x ,\x});
\draw[line width=1pt, color=black, smooth, samples=100, domain=-1.2:6] plot(\x,{\x});
\draw[color=red , thick,<->] (0.3,-2)--(1.7,-2);
\draw[line width=0.1pt, color=black, dashed](1,0)|-(0,-2);
\draw[line width=0.1pt, color=black, dashed](4.4816,0)|-(0,4.4816);
\node[black, rotate=45] at (3,3.4) {$(\Delta):y = x$}; % y = x
\node[black] at (4.4816,0) {{\tiny \ding{53}}};
\node[left,yshift=-1mm] at (0,4.6) {{\small $e^{\frac{3}{2}}$}};
\node[left,yshift=-2.5mm] at (4.8,0) {{\small $e^{\frac{3}{2}}$}};
\node[left,yshift=-2mm] at (2.9,-0.1) {{\small $e$}};
\node[black] at (0,4.4816) {{\tiny \ding{53}}};
\node[black] at (2.7182,0) {{\tiny \ding{53}}};
\draw[color=red , thick, ->] (0,0)--(0,-0.9);
\draw[color=red , thick, ->] (-2,1)--(-2,1.7);
\begin{scriptsize}
\draw[color=blue] (2.8,1.4) node {$(C_f)$};
\end{scriptsize}
\end{axis}
\end{tikzpicture}
\end{document}
但它没有给我相同的结果 + 我得到了一些错误,我不知道如何修复它们
答案1
分析、调试……:
- 全部评论
- 逐步评论
- 做一些代码格式化和注释
- 揭示 4 个未使用的包
你的问题是,你不能通过简单地“交换”变量来计算逆:
\draw[line width=1pt, color=blue, smooth, samples=100, domain=-2:6] plot({2 *\x * ln \x - 2*\x ,\x});
建议:
- 通过删除内联计算
\draw
- 存储为(表格)数据
- 读取所述数据,包括交换列和不交换列
- 情节
pgfplot
更加一致地使用
\documentclass[border=12pt]{standalone}
%\usepackage{tikz,tkz-base,tkz-tab}
\usepackage{tikz}
%\usetikzlibrary{positioning}
\usepackage{pifont}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,%>=triangle 45,
x=1cm,y=1cm]
\begin{axis}[scale=1.3, x=1cm, y=1cm, axis lines=middle,
xmin=-3.5, xmax=7, ymin=-3, ymax=6,
xtick={-3,...,6}, ytick={-2,...,5},]
% ~~~ function C_f ~~~~~~~~~~~~~~~~
\draw[line width=1pt, color=blue, smooth, samples=100, domain=0:6.5] plot(\x,{2 *\x * ln \x - 2*\x });
% ~~~ "inverse" ~~~ No ~~~~~~~~~~~~~~~
% \draw[line width=1pt, color=blue, smooth, samples=100, domain=-2:6] plot({2 *\x * ln \x - 2*\x ,\x});
% ~~~ diagonal ~~~~~~~~~~
\draw[line width=1pt, color=black, smooth, samples=100, domain=-1.2:6] plot(\x,{\x});
% ~~~ labels, marks etc. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\draw[color=red , thick,<->] (0.3,-2)--(1.7,-2);
\draw[line width=0.1pt, color=black, dashed](1,0)|-(0,-2);
\draw[line width=0.1pt, color=black, dashed](4.4816,0)|-(0,4.4816);
\node[black, rotate=45] at (3,3.4) {$(\Delta):y = x$}; % y = x
\node[black] at (4.4816,0) {{\tiny \ding{53}}};
\node[left,yshift=-1mm] at (0,4.6) {{\small $e^{\frac{3}{2}}$}};
\node[left,yshift=-2.5mm] at (4.8,0) {{\small $e^{\frac{3}{2}}$}};
\node[left,yshift=-2mm] at (2.9,-0.1) {{\small $e$}};
\node[black] at (0,4.4816) {{\tiny \ding{53}}};
\node[black] at (2.7182,0) {{\tiny \ding{53}}};
\draw[color=red , thick, ->] (0,0)--(0,-0.9);
\draw[color=red , thick, ->] (-2,1)--(-2,1.7);
\begin{scriptsize}
\draw[color=blue] (2.8,1.4) node {$(C_f)$};
\end{scriptsize}
\end{axis}
\end{tikzpicture}
\end{document}
答案2
以下是如何在 中执行此操作的草图pgfplots
,其中显示了大多数(并非全部)必需的功能。目前,在情节范围tikz
内使用超出了我的范围 ;-) 请根据需要进行改进。coordinate system
关键思想:
- 将所需的 3 个函数计算为数据表(在本例中为手动)
- 打开主电网
- 根据需要贴上一些标签和标记
暗示:
\addplot ... ;
似乎定义了一条路径- 这就是为什么你可以在它后面放置任意数量的节点
- 这是放置文本、符号等的一种方式。
将函数数据保存为fnc.dat
:
x y
0 0
0.1 -0.6605170
0.5 -1.6931472
1.0 -2.
1.5 -1.7836047
2.0 -1.2274113
2.5 -0.4185463
3.0 0.5916737
3.5 1.7693408
4.0 3.0903549
4.5 4.5366966
5.0 6.0943791
5.5 7.7522290
仅交换数据并保存为inv.dat
:
x y
0 0
-0.6605170 0.1
-1.6931472 0.5
-2. 1.0
-1.7836047 1.5
-1.2274113 2.0
-0.4185463 2.5
0.5916737 3.0
1.7693408 3.5
3.0903549 4.0
4.5366966 4.5
6.0943791 5.0
7.7522290 5.5
因为它非常简单所以我们也保存它lin.dat
,或者在 pgfplots 中计算它:
x y
-3 -3
7 7
\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={$C_f(x)$ and its inverse},
xlabel={$x$},
ylabel={$y$},
grid=major,
]
% ~~~ function ~~~~~~~~~~~~~~~~~~~~~~~~
\addplot[blue ] table {fnc.dat}
%~~~ marking zero ~~~~
node[pos=.38,circle,draw] {}
% ~~~ putting text ~~~~~~
node[pos=.38,xshift=5mm,yshift=-3mm] {$(e,0)$}
% ~~~ name of the curve ~~~~~~~
[xshift=15pt]% moving the label to right of curve
node[pos=.5] {$(C_f)$};
% ~~~ inverse ~~~~~~~~~~~~~~~~~~~~~~~~
\addplot[black] table {inv.dat}
[yshift=4mm,xshift=-2mm]
node[pos=.3] {inverse};
% ~~~ linear ~~~~~~~~~~~~~~~~~~~~~~~~
\addplot[green!80!black!100] table {lin.dat}% could be calculated
%~~~ marking intersection ~~~~
node[pos=.74,circle,draw] {}
% ~~~ putting text ~~~~~~
node[pos=.74,xshift=8mm,yshift=-3mm] {$(e^{1.5},e^{1.5})$}
% ~~~ name of the curve ~~~~~~~~~~
[yshift=3mm]
node[pos=.45,sloped] {$(\Delta):y = x$};
\end{axis}
\end{tikzpicture}
\end{document}
答案3
使用tzplot
:
反函数:tzfn'
\documentclass{standalone}
\usepackage{tzplot}
\begin{document}
\begin{tikzpicture}[font=\scriptsize]
\tzhelplines[thick](-4,-3)(8,8)
\tzaxes(-4,-3)(8,8){$x$}{$y$}
\tzshoworigin
\tzticks{-3,-2,-1,1,2,...,7}{-2,-1,1,2,...,7}
\def\Gx{2*\x*ln(\x)-2*\x}
\def\ray{\x}
\tzfn\ray[-2:7]{$y=x$}[r]
\tzfn[blue]\Gx[.001:5]{$g$}[a]
\tzfn'[red]\Gx[1:5]{$g^{-1}$}[r] % inverse function
\end{tikzpicture}
\end{document}
完整代码
\documentclass{standalone}
\usepackage{tzplot}
\begin{document}
\begin{tikzpicture}[font=\scriptsize]
\tzhelplines(-4,-3)(8,8)
\tzaxes(-4,-3)(8,8){$x$}{$y$}
\tzshoworigin
\tzticks{-3,-2,-1,1,2,...,7}{-2,-1,1,2,...,7}
% graphs
\def\Gx{2*\x*ln(\x)-2*\x}
\def\ray{\x}
\tzfn\ray[-2:7]{$y=x$}[r]
\tzfn[blue]"Gx"\Gx[.001:5]{$g$}[a]
\tzfn'[red]"iGx"\Gx[1:5]{$g^{-1}$}[r] % inverse function
% slopes and intersections
\tzXpoint*{Gx}{iGx}(X)
\tzslopeat[<->,red]{Gx}{1}{1cm}
\tzline+[->,red,thick](-2,1)(0,.5) % ad hoc
\tzproj*(1,-2)
\tzXpoint*[blue]{Gx}{axes}(ex){$e$}[b] % y-intercept
\tzXpoint*[red]{iGx}{axes}(ey){$e$}[l] % x-intercept
\end{tikzpicture}
\end{document}
答案4
感谢你们
我实际上通过将域名从 更改为domain=-2:6
来解决这个问题domain=1:6
我在交换变量时忘记交换域
\documentclass[border=12pt]{standalone}
%\usepackage{tikz,tkz-base,tkz-tab}
\usepackage{tikz}
%\usetikzlibrary{positioning}
\usepackage{pifont}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,%>=triangle 45,
x=1cm,y=1cm]
\begin{axis}[scale=1.3, x=1cm, y=1cm, axis lines=middle,
xmin=-3.5, xmax=7, ymin=-3, ymax=6,
xtick={-3,...,6}, ytick={-2,...,5},]
% ~~~ function C_f ~~~~~~~~~~~~~~~~
\draw[line width=1pt, color=blue, smooth, samples=100, domain=0:6.5] plot(\x,{2 *\x * ln \x - 2*\x });
\draw[line width=1pt, color=blue, smooth, samples=100, domain=1:6] plot({2 *\x * ln \x - 2*\x ,\x});
% ~~~ diagonal ~~~~~~~~~~
\draw[line width=1pt, color=black, smooth, samples=100, domain=-1.2:6] plot(\x,{\x});
% ~~~ labels, marks etc. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\draw[color=red , thick,<->] (0.3,-2)--(1.7,-2);
\draw[line width=0.1pt, color=black, dashed](1,0)|-(0,-2);
\draw[line width=0.1pt, color=black, dashed](4.4816,0)|-(0,4.4816);
\node[black, rotate=45] at (3,3.4) {$(\Delta):y = x$}; % y = x
\node[black] at (4.4816,0) {{\tiny \ding{53}}};
\node[left,yshift=-1mm] at (0,4.6) {{\small $e^{\frac{3}{2}}$}};
\node[left,yshift=-2.5mm] at (4.8,0) {{\small $e^{\frac{3}{2}}$}};
\node[left,yshift=-2mm] at (2.9,-0.1) {{\small $e$}};
\node[black] at (0,4.4816) {{\tiny \ding{53}}};
\node[black] at (2.7182,0) {{\tiny \ding{53}}};
\draw[color=red , thick, ->] (0,0)--(0,-0.9);
\draw[color=red , thick, ->] (-2,1)--(-2,1.7);
\begin{scriptsize}
\draw[color=blue] (2.8,1.4) node {$(C_f)$};
\end{scriptsize}
\end{axis}
\end{tikzpicture}
\end{document}