2

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}
3
  • 2
    Are you actually plotting anything numerical? If not, I'd say using tikzpicture without axis saves your brain cells. BTW what you want is probably a \clip(430,0)rectangle(925,1000?);
    – Symbol 1
    Sep 4, 2021 at 6:39
  • @Symbol1 there were some numerical components for earlier graphs. Thank you so much! \clip worked perfectly :))
    – raynerk
    Sep 4, 2021 at 6:50
  • @Symbol1, do you want to write an answer, shall search for a duplicate or simply close it as "solved in the comments"? Sep 5, 2021 at 14:50

1 Answer 1

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .