我正在尝试遮蔽该图表下的区域:
\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}
我所做的就是填充我画的线,然后在其正下方画一个三角形来填充其余区域。最终,这足以达到我想要的图片效果,但我认为会有比我所做的更简单、更有效的方法。
谢谢!
答案1
\addplot
也许最简单的选择是使用 和fill
以及来绘制曲线\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}
fillbetween
如果您加载该库,则会有更多选项可用。
\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}