2

I am trying to shade the area under this graph:

\begin{tikzpicture}[scale=1.5,line width=1pt]

\begin{axis}[
color= black,
xmin=0, 
xmax=1250, 
ymin=0, 
ymax=1250, 
axis equal image, 
axis x line=left,
axis y line=middle,
%xticklabels={}, 
%yticklabels={},
font=\scriptsize,
%ticks=none,
%extra x ticks=0,
%extra y ticks=0,
xlabel={Corn},
ylabel={Tomatoes},
]

%\draw (0,675) -- (1000,0);
\draw [thick, red] plot [smooth] coordinates {(0,675) (200,650) (400,600) 
(600,500) (800,300) (1000,0)};
%\draw [thick, red!20, fill=red!20] (0,0) -- (0,675) -- (1000,0) -- cycle;
\filldraw[black] (0,675) circle (0.03cm) node[above right, scale=0.9] 
{$(0,675)$};
\filldraw[black] (200,650) circle (0.03cm) node[below, scale=0.9] 
{$(200,650)$};
\filldraw[black] (400,600) circle (0.03cm) node[above right, scale=0.9] 
{$(400,600)$};
\filldraw[black] (600,500) circle (0.03cm) node[above right, scale=0.9] 
{$(600,500)$};
\filldraw[black] (800,300) circle (0.03cm) node[above right, scale=0.9] 
{$(800,300)$};
\filldraw[black] (1000,0) circle (0.03cm) node[above right, scale=0.9] 
{$(1000,0)$};

\end{axis}

\end{tikzpicture}

What I had done was filled in the line that I drew and then drew a triangle right under it to fill in the rest of the area. Ultimately, this would suffice for what I wanted to have as the picture, but I figured that there would be an easier and more effective way than what I am doing.

Thanks!

3

The perhaps simplest option is to draw the curve with \addplot and use fill as well as \closedcycle.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[scale=1.5,line width=1pt]

\begin{axis}[
color= black,
xmin=0, 
xmax=1250, 
ymin=0, 
ymax=1250, 
axis equal image, 
axis x line=left,
axis y line=middle,
%xticklabels={}, 
%yticklabels={},
font=\scriptsize,
%ticks=none,
%extra x ticks=0,
%extra y ticks=0,
xlabel={Corn},
ylabel={Tomatoes},
]

%\draw (0,675) -- (1000,0);
\addplot [thick, red,fill=blue,smooth] coordinates {(0,675) (200,650) (400,600) 
(600,500) (800,300) (1000,0)} \closedcycle;
%\draw [thick, red!20, fill=red!20] (0,0) -- (0,675) -- (1000,0) -- cycle;
\filldraw[black] (0,675) circle (0.03cm) node[above right, scale=0.9] 
{$(0,675)$};
\filldraw[black] (200,650) circle (0.03cm) node[below, scale=0.9] 
{$(200,650)$};
\filldraw[black] (400,600) circle (0.03cm) node[above right, scale=0.9] 
{$(400,600)$};
\filldraw[black] (600,500) circle (0.03cm) node[above right, scale=0.9] 
{$(600,500)$};
\filldraw[black] (800,300) circle (0.03cm) node[above right, scale=0.9] 
{$(800,300)$};
\filldraw[black] (1000,0) circle (0.03cm) node[above right, scale=0.9] 
{$(1000,0)$};

\end{axis}

\end{tikzpicture}
\end{document}

enter image description here

More options become available if you load the fillbetween library.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}[scale=1.5,line width=1pt]

\begin{axis}[
color= black,
xmin=0, 
xmax=1250, 
ymin=0, 
ymax=1250, 
axis equal image, 
axis x line=left,
axis y line=middle,
%xticklabels={}, 
%yticklabels={},
font=\scriptsize,
%ticks=none,
%extra x ticks=0,
%extra y ticks=0,
xlabel={Corn},
ylabel={Tomatoes},
]

%\draw (0,675) -- (1000,0);
\addplot [thick, red,smooth,name path=A] coordinates {(0,675) (200,650) (400,600) 
(600,500) (800,300) (1000,0)} ;
\addplot [name path=B,draw=none] coordinates {(0,0) (1000,0)};
\addplot [orange] fill between [of=A and B];
%\draw [thick, red!20, fill=red!20] (0,0) -- (0,675) -- (1000,0) -- cycle;
\filldraw[black] (0,675) circle (0.03cm) node[above right, scale=0.9] 
{$(0,675)$};
\filldraw[black] (200,650) circle (0.03cm) node[below, scale=0.9] 
{$(200,650)$};
\filldraw[black] (400,600) circle (0.03cm) node[above right, scale=0.9] 
{$(400,600)$};
\filldraw[black] (600,500) circle (0.03cm) node[above right, scale=0.9] 
{$(600,500)$};
\filldraw[black] (800,300) circle (0.03cm) node[above right, scale=0.9] 
{$(800,300)$};
\filldraw[black] (1000,0) circle (0.03cm) node[above right, scale=0.9] 
{$(1000,0)$};

\end{axis}

\end{tikzpicture}
\end{document}

enter image description here

  • Awesome. This is exactly what I was looking for, thank you! – Aiden Kenny Sep 14 '18 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.