我曾经rotate=-90 degrees
绘制 x=y^2+1,抛物线在两端获得半箭头,在 x 轴的顶点获得一个箭头。
\draw[ultra thick,rotate=-90] (0,1) parabola (1,2);
\draw[ultra thick,rotate=-90] (0,1) parabola (-1,2);
我想了解为什么会发生这种情况以及如何摆脱这些箭头。
\documentclass[border=3pt]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{patterns,arrows.meta,calc,decorations.pathmorphing}
\usepackage{tikz-3dplot}
\pgfplotsset{compat=1.15}
\newcommand{\betkz}{\begin{tikzpicture}}
\newcommand{\etkz}{\end{tikzpicture} }
\def\myarrow{-{Latex[length=2mm]}}
\begin{document}
\betkz
%dr%axis
\draw[\myarrow] (-2,0)--(3,0) node [right,scale=1.2] {$x$};
\draw[scale=1,\myarrow] (0,-2)--(0,1.5) node [scale=1.2,right] {$ y$};
\foreach \x in {0,...,2}
\draw (\x,1pt) -- (\x,-3pt)
node[scale=0.8,anchor=south east] {\x};
\foreach \y in {-1}
\draw (1pt,\y) -- (-3pt,\y)
node[scale=0.8,anchor=north east] {\y};
\foreach \y in {1}
\draw (1pt,\y) -- (-3pt,\y)
node[anchor=east] {\y};
%draw graph
\draw[ultra thick,rotate=-90] (0,1) parabola (1,2);
\draw[ultra thick,rotate=-90] (0,1) parabola (-1,2);
\fill [gray, opacity=0.2, domain=-1:1, variable=\x]
(-1,-1 )
-- plot ({\x}, {\x})
-- (1, -1)
-- cycle;
\fill [gray, opacity=0.2, domain=1:2, variable=\x]
(1,0 )
-- plot ( 1,{sqrt(\x-1)})
-- (2, 1)
-- cycle;
\fill [white, opacity=1, domain=1:2, variable=\x]
(1,0 )
-- plot ( {\x},{sqrt(\x-1)})
-- (2, 1)
-- cycle;
\fill [gray, opacity=0.2, domain=1:2, variable=\x]
(1,0 )
-- plot ( 1,{-sqrt(\x-1)})
-- (2, -1)
-- cycle;
\fill [white, opacity=1, domain=1:2, variable=\x]
(1,0 )
-- plot ( {\x},{-sqrt(\x-1)})
-- (2, -1)
-- cycle;
\draw[thick] (-1,-1)--(1,1);
\draw[thick] (1,1)--(2,1);
\draw[thick] (-1,-1)--(2,-1);
\draw[thin] (2,-1)--(2,1);
\draw[thin] (1,-1)--(1,1);
\node at (.5,-0.5) {$D$};
\node[scale=0.5,rotate=-40] at (1.5,-.5) {$x=y^2+1$};
\end{tikzpicture}
\end{document}
答案1
它们实际上不是箭头,但你只是在部分线条上填充了白色。从这张图片中可能更容易看到:
由以下代码实现:
\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[ultra thick,rotate=-90] (0,1) parabola (1,2);
\draw[ultra thick,rotate=-90] (0,1) parabola (-1,2);
\filldraw [fill=white, draw=red,ultra thin, opacity=1, domain=1:2, variable=\x]
(1,0 )
-- plot ( {\x},{sqrt(\x-1)})
-- (2, 1)
-- cycle;
\end{tikzpicture}
\end{document}
您用填充覆盖了一半的线条,但由于您使用的坐标,端点处理得不好。一种可能的解决方法是将填充路径更改为
\filldraw [fill=white, draw=red,ultra thin, opacity=1, domain=1:2, variable=\x]
(1,0 )
-- plot ( {\x},{sqrt(\x-1)})
-- ++(0.1,0) % coordinate relative to the previous one
|- cycle;
但我并不认为这是一个好的解决办法。
稍微好一点的选择是将抛物线的绘制移到填充之后,并从 更改ultra thick
为thick
。
但我更愿意建议使用单一路径进行绘图和填充,例如:
\filldraw [fill=gray,fill opacity=0.2, draw=black,thick,samples=201]
(1,0)
-- plot[domain=1:2] ({\x},{-sqrt(\x-1)})
-- (-1,-1)
-- (1,1)
-- (2,1)
-- plot[domain=2:1] ({\x},{sqrt(\x-1)})
-- cycle;
除此之外,我还为 制作了新样式myarrow
,而不是宏。虽然两者都适用于这种情况,但如果您添加的选项不仅仅是箭头,宏将不起作用。
虽然完全取决于你,但我不确定你是否真的从\betkz
/\etkz
宏中获得了很多,所以我只会使用原始形式。
\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns,arrows.meta,calc,decorations.pathmorphing}
\tikzset{
myarrow/.style={-{Latex[length=2mm]}}
}
\begin{document}
\begin{tikzpicture}
%dr%axis
\draw[myarrow] (-2,0)--(3,0) node [right,scale=1.2] {$x$};
\draw[scale=1,myarrow] (0,-2)--(0,1.5) node [scale=1.2,right] {$ y$};
\foreach \x in {0,...,2}
\draw (\x,1pt) -- (\x,-3pt)
node[scale=0.8,anchor=south east] {\x};
\foreach \y in {-1}
\draw (1pt,\y) -- (-3pt,\y)
node[scale=0.8,anchor=north east] {\y};
\foreach \y in {1}
\draw (1pt,\y) -- (-3pt,\y)
node[anchor=east] {\y};
%draw graph
\filldraw [fill=gray,fill opacity=0.2, draw=black,thick,samples=201]
(1,0)
-- plot[domain=1:2] ({\x},{-sqrt(\x-1)})
-- (-1,-1)
-- (1,1)
-- (2,1)
-- plot[domain=2:1] ({\x},{sqrt(\x-1)})
-- cycle;
\draw[thick] (-1,-1)--(1,1);
\draw[thick] (1,1)--(2,1);
\draw[thick] (-1,-1)--(2,-1);
\draw[thin] (2,-1)--(2,1);
\draw[thin] (1,-1)--(1,1);
\node at (.5,-0.5) {$D$};
\node[scale=0.5,rotate=-40] at (1.5,-.5) {$x=y^2+1$};
\end{tikzpicture}
\end{document}