我是 Latex 的新手,几天来我一直在论坛上研究这么多曲线。我已经设法画出曲线,但标记现在是一项艰巨的任务。这只是应该显示截距和固定点的参数值。不按比例。
下面是我从这里得到的用于获取图表的代码组合:
\documentclass[tikz,border={15mm 15mm 15mm 15mm},]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\pgfplotsset{
every non boxed x axis/.style={
xtick align=center,
enlarge x limits=true,
x axis line style={line width=0.8pt, -latex}
},
every boxed x axis/.style={}, enlargelimits=false
}
\pgfplotsset{
every non boxed y axis/.style={
ytick align=center,
enlarge y limits=true,
y axis line style={line width=0.8pt, -latex}
},
every boxed y axis/.style={}, enlargelimits=false
}
\usetikzlibrary{
arrows.meta,
intersections,
}
\usetikzlibrary{calc}
%\pgfplotsset{compat=newest}
\usetikzlibrary{
arrows.meta,
intersections,}
% arrows as stealth fighters
\tikzset{>=stealth}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
axis line style=<->,
xmin=-5,xmax=8,
ymin=-5,ymax=8,
xlabel=$N_A$,
ylabel=$N_B$,
xtick=\empty,
ytick=\empty,
xticklabels=\empty,
yticklabels=\empty,
]%\addplot[thick,domain=0:7,blue,name path = A] {x } coordinate[pos=0.4] (m) ;
\addplot[thick,domain=-5:7,blue,name path = A] ({0.5* x^2-2},{x}) coordinate[pos=0.4] (m) ;
\addplot[thick,domain=-5:7,blue,name path = B] ({ x+2},{x}) coordinate[pos=0.4] (n) ;
% \draw[densely dashed, name path=D] (0,4) -|node[pos=0.15, color=black, label=below:$\lambda x_{1}+ (1-\lambda)x_{2}$] {} node[pos=-2, fill,circle,inner sep=1pt] {}(m);
%\addplot[smooth,thick, blue,-]({x^2-2},{x});
%\addplot[smooth,thick, red,-]({x+1},{x});
% \coordinate (Ux) at (\x,{(\x)});
\path [name intersections={of=A and B, by={a}}] node[fill,circle,inner sep=1pt] at (a) {};
\draw[densely dashed, name path=c ] (0,0) -|node[pos=0.6, color=black, label=below:$b$] {}(n);
\draw[densely dashed] (0,0) -| node[pos=0.5, color=black, label=below:$x_{1}$] {}(m);
\path [name intersections={of=B and A, by={c}}] node[fill,circle,inner sep=1pt] at (c) {};
\end{axis}
\end{tikzpicture}
\end{document}
这就是我得到的:
答案1
有必要写这么复杂的代码吗?
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[scale=0.6,>=stealth,
dot/.style={circle,fill=black,inner sep=1pt}]
\draw[blue,thick] plot[samples=100,domain=-4:4.2] (0.5*\x*\x-2,\x);
\draw[blue,thick] plot[domain=-5:5] (\x+2,\x);
\draw[->] (-3,0) -- (8,0) node[above] {$x$};
\draw[->] (0,-5) -- (0,5) node[left] {$y$};
% The following coordinates are calculated using some (very simple) maths.
% For more complicated plots, you may need `intersections' library, but it
% is not necessary here
\path (2,0) node[dot,label=below:$a$] {}
(6,4) node[dot] {}
(0,2) node[dot,label=above left:$c$] {}
(0,-2) node[dot] {} node[above right=-5pt and 2pt] {$d$};
\draw[dashed] (6,4) -- (6,0) node[below] {$b$};
\end{tikzpicture}
\end{document}
答案2
尽管我同意 Joule V 的观点,即这个图可以不用pgfplots
,但当你处理更复杂的函数时,使用 后者会有所回报,因为这些函数可能会dimension too large
在普通的 Ti 中引发错误钾Z。还pgfplots
可以确保您获得正确尺寸的图。它还有一个优点,即xmin
等存储在 pgf 键中,这表面上使代码更长,但实际上使其更通用,即
\path[name path=yaxis] (0,\pgfkeysvalueof{/pgfplots/ymin}) -- (0,\pgfkeysvalueof{/pgfplots/ymax});
可以在任何代码中工作,并且如果您想构建其他示例,则不必进行调整。
\documentclass[tikz,border={15mm 15mm 15mm 15mm}]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\pgfplotsset{
every non boxed x axis/.style={
xtick align=center,
enlarge x limits=true,
x axis line style={line width=0.8pt, -latex}
},
every boxed x axis/.style={}, enlargelimits=false
}
\pgfplotsset{
every non boxed y axis/.style={
ytick align=center,
enlarge y limits=true,
y axis line style={line width=0.8pt, -latex}
},
every boxed y axis/.style={}, enlargelimits=false
}
\usetikzlibrary{
arrows.meta,
intersections,
}
\usetikzlibrary{calc}
%\pgfplotsset{compat=newest}
\usetikzlibrary{
arrows.meta,
intersections,}
% arrows as stealth fighters
\tikzset{>=stealth}
\begin{document}
\begin{tikzpicture}[bullet/.style={fill,circle,inner sep=1.5pt}]
\begin{axis}[
axis lines=middle,
axis line style=<->,
xmin=-5,xmax=8,
ymin=-5,ymax=8,
xlabel=$N_A$,
ylabel=$N_B$,
xtick=\empty,
ytick=\empty,
xticklabels=\empty,
yticklabels=\empty,
]
\addplot[thick,domain=-5:7,blue,name path=A,smooth] ({0.5* x^2-2},{x}) coordinate[pos=0.4] (m) ;
\addplot[thick,domain=-5:7,blue,name path=B] ({ x+2},{x}) coordinate[pos=0.4] (n) ;
\path[name path=yaxis] (0,\pgfkeysvalueof{/pgfplots/ymin}) -- (0,\pgfkeysvalueof{/pgfplots/ymax});
\path[name path=xaxis] (\pgfkeysvalueof{/pgfplots/xmin},0) --
(\pgfkeysvalueof{/pgfplots/xmax},0);
\path [name intersections={of=A and B, by={d,b}}]
(d) node[bullet,label=below right:$d$] {}
(b) node[bullet,label=below right:$b$] {};
\draw[densely dashed] (b) -- (b|-0,0);
\path [name intersections={of=A and yaxis, by={aux,c}}]
(c) node[bullet,label=above left:$c$] {};
\path [name intersections={of=B and xaxis, by={a}}]
(a) node[bullet,label=below right:$a$] {};
\end{axis}
\end{tikzpicture}
\end{document}