Can I restrict domain on \draw for pgfplots

pgfplotstikz-pgf

I am trying to draw the same curve but with anything before the point (430) cut off. However, I am currently getting an error, supposedly as I'm not adding a plot but instead using \draw . How could I tweak my source to account for this?

\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}

Best Answer

Use \clip (with or without {scope}) to trim unwanted part of your graph

\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}

a pgfplots box with drawing clipped

Related Question