我试图绘制相同的曲线,但在点 (430) 截止之前使用任何内容。但是,我目前收到错误,据说是因为我没有添加绘图,而是使用了 \draw 。我该如何调整源代码以解决这个问题?
\begin{center}
\begin{tikzpicture}
\begin{axis}[
title={\textbf{Supply Curve for Firm at Price P\textsubscript{2}}},
scale = 1.2,
axis lines = middle,
xmin = 0, xmax = 1000,
ymin = 0, ymax = 1000,
axis lines* = left,
xtick={0,570}, ytick={365},
xticklabels={0,Q\textsubscript{2}}, yticklabels={P\textsubscript{2}},
clip = false,
]
\node [right] at (current axis.right of origin) {Q};
\node [above] at (current axis.above origin) {P (\$)};
\draw[purple, thick] (0,0) -- (0,365);
\draw[thick,purple,restrict x to domain=430:925] (100,400) to [out=300,in=260] (775,925);
\node[right] at (775,925) {\textcolor{Purple}{\scriptsize MC=S}};
\end{axis}
\end{tikzpicture}
\end{center}
答案1
使用\clip
(有或无{scope}
)来修剪图形中不需要的部分
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={\textbf{Supply Curve for Firm at Price P\textsubscript{2}}},
xmin = 0, xmax = 1000, ymin = 0, ymax = 1000,
xtick={0,570}, xticklabels={0,Q\textsubscript{2}},
ytick={365},yticklabels={P\textsubscript{2}},
clip = false,
]
\node [right] at (current axis.right of origin) {Q};
\node [above] at (current axis.above origin) {P (\$)};
\draw[purple, thick] (0,0) -- (0,365);
\begin{scope}
\clip(430,0)rectangle(925,1000);% <--- use \clip to limit drawings in region
\draw[thick,purple,] (100,400) to [out=300,in=260] (775,925);
\end{scope}% <--- use \scope the limit the lifetime of \clip
\node[right] at (775,925) {\textcolor{purple}{\scriptsize MC=S}};
\end{axis}
\end{tikzpicture}
\end{document}