我正在尝试填充曲线上方和直线下方的区域,但曲线有问题,有一块区域无法填充!谢谢!
\begin{tikzpicture}
\draw[thick,<->](0,6.5) node[above]{$p$}--(0,0)--(6.5,0) node[right]{$Q$};
\draw(0,6)--(5,0) node[above right]{$D(p_t)$};
\draw(0,0) ..controls (4.3,1.5) and (6,6) .. (6,6) node[right]{$C(Q_t)$};
\draw[dashed] (0,2.05) node[left]{$p_t$}--(3.3,2.05)--(3.3,0)node[below]{$Q_t$};
\path[pattern=north east lines] (0,2.05)--(3.3,2.05)--(0,6);
\path[pattern=north east lines] (0,2.05)--(3.3,2.05)--(0,0);
\end{tikzpicture}
答案1
我不确定您想要为图表的哪一部分添加阴影。一种直接的方法是使用\clip
:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\draw[thick, <->]
(0,6.5) node[above] {$p$} --
(0,0) --
(6.5,0) node[right] {$Q$};
\draw
(0,6) --
(5,0) node[above right]{$D(p_t)$};
\draw
(0,0) .. controls (4.3,1.5) and (6,6) ..
(6,6) node[right] {$C(Q_t)$};
\begin{scope}
\clip
(0,0) .. controls (4.3,1.5) and (6,6) ..
(6,6) -- (0,6) -- cycle;
\path[pattern=north east lines]
(0,0) -- (5,0) -- (0,6) -- cycle;
\end{scope}
\draw[dashed]
(0,2.05) node[left] {$p_t$} --
(3.3,2.05) --
(3.3,0) node[below] {$Q_t$};
\end{tikzpicture}
\end{document}
为了获得更大的灵活性并减少路径的重复使用,您还可以使用fillbetween
提供的库pgfplots
(也会加载tikz
):
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{patterns, fillbetween}
\begin{document}
\begin{tikzpicture}
\draw[thick, <->]
(0,6.5) node[above] {$p$} --
(0,0) --
(6.5,0) node[right] {$Q$};
\draw
(0,6) --
(5,0) node[above right]{$D(p_t)$};
\draw[name path=curve]
(0,0) .. controls (4.3,1.5) and (6,6) ..
(6,6) node[right] {$C(Q_t)$};
\draw[dashed, name path=segment]
(0,2.05) node[left] {$p_t$} --
(3.3,2.05) --
(3.3,0) node[below] {$Q_t$};
\path[pattern=north east lines]
(0,2.05) -- (3.3,2.05) -- (0,6) -- cycle;
\fill[
pattern=north west lines,
intersection segments={
of={curve and segment},
sequence={L1 -- R1[reverse]}
}
] -- cycle;
\end{tikzpicture}
\end{document}