我需要在 中繪製下圖LaTeX
。
正如所建議的,我自己嘗試了一些東西,到目前為止我已經達到了以下目標:
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta,automata,topaths}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
axis line style={-Stealth,very thick},
xmin=0,xmax=5.5,ymin=-5.5,ymax=6.5,
xtick distance=1,
xticklabels={,,},
ytick distance=1,
yticklabels={,,},
xlabel=$\theta$,
ylabel=Net Utility,
grid=major,
grid style={thin,densely dotted,black!20}]
\addplot [domain=0:5,samples=2] {x*2/3-0.5} node[right]{$N (Incumbent)$}; %These are not shown completely
\addplot [domain=0:5,samples=2] {x*2-4.5} node[right]{$P (new entrant)$}; %These are not shown completely
\addplot +[-Stealth,very thick,mark=none] coordinates {(5, -5.4) (5, 6.4)}; %Why is it brown colored? and how can I put the ticks in this one too?
\addplot +[mark=none] coordinates {(3, 0) (3, 4.4)};
\addplot +[mark=none] coordinates {(4.2, 0) (4.2, 4.4)}; %Why is this blue colored?
\draw (80,465)node[]{$\frac{p_{N}}{Q_{N}}$}; %What do these mean? (80,465)
\draw (240,465)node[]{$\frac{p_{P}}{Q_{P}}$};
\draw (340,465)node[]{$\frac{p_{P}-p_{N}}{Q_{P}-Q_{N}}$};
\addplot +[Stealth-Stealth,very thick,mark=none] coordinates {(3, 4.2) (4.2, 4.2)};
\draw (365,1055)node[]{$\frac{1}{p_{P}-p_{N}}$};
\addplot[red,mark=*] coordinates {(0.75,0)};
\addplot[red,mark=*] coordinates {(2.25,0)};
\addplot[red,mark=*] coordinates {(3,0)};
\addplot[red,mark=*] coordinates {(3,1.5)};
\addplot[red,mark=*] coordinates {(4.2,0)};
\end{axis}
\end{tikzpicture}
\end{document}
但我的嘗試存在一些問題(我在上面程式碼中對應行前面也註解了我無法理解的問題):
- 我無法理解我用來顯示圖中標籤的節點座標(例如
\draw (80,465)node[]{$\frac{p_{N}}{Q_{N}}$};
)以及它們如何放置標籤。我的意思是它已經完成了我想要的事情,而且還可以。我只是不明白。我希望使用座標(0.75,-1)
(現在所在的位置$\frac{p_{N}}{Q_{N}}$
),但它不起作用並將標籤放在沒有意義的地方 - (我意識到了這一點,只需添加
black
到括號內就可以了)一些線段已自動著色為藍色或棕色。我喜歡紅色的,讓情節更優雅,但不知道如何將藍色和棕色的改回黑色。 - (我也想到了這一點。必須將 xmax 更改為更大的數字。)第 20 行和第 21 行中的標籤被修剪並且未完全顯示。
- 如何在右側垂直線上與左側垂直線上一樣打勾?
答案1
繪圖更tikz
簡單:
\documentclass[tikz, border=5mm]{standalone}
%\usepackage{pgfplots}
\usetikzlibrary{arrows.meta,
calc,
intersections
}
%\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}[y=5mm,
> = Straight Barb,
arr/.style = {-Stealth, thick},
dot/.style = {circle, fill, minimum size=3pt,
inner sep=0pt, outer sep=0pt},
every label/.style = {label distance=2pt, fill=white,
inner sep=1pt, font=\footnotesize}
]
% axis
\draw[arr, name path=A]
(-0.2,0) -- (6,0) node[below left] {$\theta$};
\draw[arr] (0,-5.0) -- (0,6) node[below right] {Net utility};
\draw[arr] (5,-5.0) -- (5,6);
\draw[densely dotted, gray]
(0,-5) grid[xstep=1, ystep=0.8] (6,6);
\coordinate (O) at (0,0);
%
\draw[name path=B]
(0,-0.5) -- (5,2*5/3-0.5) node[right]{$N$ (Incumbent)};
\draw[name path=C]
(0,-4.5) -- (5,2*5-4.5) node[right]{$P$ (new entrant)};
% intersections
\path [name intersections={of=A and B, by=ab}]
node[dot, label=below:$\frac{p_N\vphantom{-}}{Q_N}$] at (ab) {};
\path [name intersections={of=A and C, by=ac}]
node[dot, label=below:$\frac{p_P\vphantom{-}}{Q_P}$] at (ac) {};
\draw [name intersections={of=B and C, by=bc}]
(bc |- O) node[dot, label={[xshift=0.7em]below:$\frac{p_P-p_N}{Q_P - Q_N}$}] {};
%
\coordinate (d) at ($(bc) + (0,4)$);
\coordinate (e) at ($(d) + (1.5,0)$);
\draw[densely dashed]
(bc |- O) -- (d)
(e) -- (e |- O) node [dot] {};
\draw[<->]
($(d) + (0,-0.5)$)
-- node[label={[yshift=-1ex]$\frac{1}{p_P-p_N}$}] {}
($(e) + (0,-0.5)$);
\end{tikzpicture}
\end{document}