我的绘图有问题,我想在 x=4000 处设置边界,但不知道怎么做。我目前的绘图如下 这是我现在的代码
\makeatletter
\newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis}
\makeatother
\pgfplotsset{only axis on top/.style={axis on top=false, after end axis/.code={
\pgfplotsset{axis line style=opaque, ticklabel style=opaque, tick style=opaque,
grid=none}\pgfplotsdrawaxis}}}
\newcommand{\drawge}{-- (rel axis cs:1,0) -- (rel axis cs:1,1) -- (rel axis cs:0,1) \closedcycle}
\newcommand{\drawle}{-- (rel axis cs:1,1) -- (rel axis cs:1,0) -- (rel axis cs:0,0) \closedcycle}
\begin{figure}[htpb]
\centering
\label{fig:p3:c1}
\begin{tikzpicture} [scale=1.5]
\begin{axis}[only axis on top,
axis line style=very thick,
axis x line=bottom,
axis y line=left,
ymin=0,ymax=10000,xmin=0,xmax=10000,
xlabel=$x_1$, ylabel=$x_2$,grid=major,
ytick={0, 2000, 4000, 6000, 8000, 10000},
xtick={0,2000, 4000, 6000, 8000, 10000},
]
\addplot [draw=none, pattern=horizontal lines, pattern color=blue!40, domain=-2000:12000]
{(100000-13*x)/15} \drawge; %wzór funkcji
\addplot [draw=none, pattern=north west lines, pattern color=blue!40, domain=-2000:12000]
{(95000-15*x)/18} \drawge;
\addplot [draw=none, pattern=horizontal lines, pattern color=blue!40, domain=-2000:12000]
{(99000-16*x)/12} \drawle;
\addplot[draw=none, pattern=horizontal lines, pattern color=black!40, domain=-2000:12000]
{(110000-14*x)/17} \drawge;
\addplot[draw=none, pattern=horizontal lines, pattern color=black!40, domain=-2000:12000]
{0*x+6000} \drawge;
\addplot[draw=none, pattern=horizontal lines, pattern color=black!40, domain=4000:4000.1]
{x} \drawge;
\addplot[very thick, domain=-2000:12000] {(100000-13*x)/15};
\addplot[very thick, domain=-2000:12000] {(95000-15*x)/18};
\addplot[very thick, domain=-2000:12000] {(99000-16*x)/12};
\addplot[very thick, domain=-2000:12000] {(110000-14*x)/17} ;
\addplot[very thick, domain=-2000:12000] {0*x+6000} ;
\addplot[very thick, domain=4000:4000.1] {x} ;
\end{axis}
\end{tikzpicture}
\caption{Problem 4, Part A}
\end{figure}
答案1
例如,可以通过指定起点和终点坐标来添加线:
\addplot[very thick] coordinates {(4000, 0) (4000, 10000)};
另外,我必须删除\pgfplotsdrawaxis
,否则,轴将被绘制两次,并且组件略有偏移,请参见第一个版本这个答案。
完整示例:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{patterns}
\makeatletter
\newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis}
\makeatother
\pgfplotsset{
only axis on top/.style={
axis on top=false,
after end axis/.code={
\pgfplotsset{
axis line style=opaque,
ticklabel style=opaque,
tick style=opaque,
grid=none,
}%
% \pgfplotsdrawaxis
},
},
}
\newcommand{\drawge}{%
-- (rel axis cs:1,0) -- (rel axis cs:1,1) -- (rel axis cs:0,1) \closedcycle
}
\newcommand{\drawle}{%
-- (rel axis cs:1,1) -- (rel axis cs:1,0) -- (rel axis cs:0,0) \closedcycle
}
\begin{document}
\begin{tikzpicture} [scale=1.5]
\begin{axis}[only axis on top,
axis line style=very thick,
axis x line=bottom,
axis y line=left,
ymin=0,
ymax=10000,
xmin=0,
xmax=10000,
xlabel=$x_1$,
ylabel=$x_2$,
grid=major,
ytick={0, 2000, 4000, 6000, 8000, 10000},
xtick={0,2000, 4000, 6000, 8000, 10000},
]
\addplot [
draw=none,
pattern=horizontal lines,
pattern color=blue!40,
domain=-2000:12000,
] {(100000-13*x)/15} \drawge; %wzór funkcji
\addplot [
draw=none,
pattern=north west lines,
pattern color=blue!40,
domain=-2000:12000,
] {(95000-15*x)/18} \drawge;
\addplot [
draw=none,
pattern=horizontal lines,
pattern color=blue!40,
domain=-2000:12000,
] {(99000-16*x)/12} \drawle;
\addplot[
draw=none,
pattern=horizontal lines,
pattern color=black!40,
domain=-2000:12000,
] {(110000-14*x)/17} \drawge;
\addplot[
draw=none,
pattern=horizontal lines,
pattern color=black!40,
domain=-2000:12000,
] {0*x+6000} \drawge;
\addplot[
draw=none,
pattern=horizontal lines,
pattern color=black!40,
domain=4000:4000.1,
] {x} \drawge;
\addplot[
very thick,
domain=-2000:12000,
] {(100000-13*x)/15};
\addplot[very thick, domain=-2000:12000] {(95000-15*x)/18};
\addplot[very thick, domain=-2000:12000] {(99000-16*x)/12};
\addplot[very thick, domain=-2000:12000] {(110000-14*x)/17};
\addplot[very thick, domain=-2000:12000] {0*x+6000};
\addplot[very thick] coordinates {(4000, 0) (4000, 10000)};
\end{axis}
\end{tikzpicture}
\end{document}