我正在使用 Tikz 绘制一个带有绝对值函数和连接两点的抛物线的简单图形。我的代码片段是:
\begin{tikzpicture}
\draw (0,0) -- (2,2);
\draw (0,0) -- (-2,2);
\draw (-0.5,0.5) parabola (1,1);
\end{tikzpicture}
但是,这会绘制一条连接 (-0.5,0.5) 和 (1,1) 的抛物线并停止在那里。有没有办法延伸抛物线的两侧?
答案1
我不太清楚你说的延伸抛物线两侧是什么意思。但也许这能帮到你。
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usepackage{helvet}
\usepackage{sansmath}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=$X$,
ylabel=$Y$,
axis x line=center, xlabel style={anchor=south west},
axis y line=center, ylabel style={anchor=south west},
xmin=-4,
xmax=4,
ymin=-1,
ymax=7,
axis line style={thick, shorten > = -0.5cm, shorten < = -0.5cm},
samples=50,
unit vector ratio*=1 1,
font=\sansmath\sffamily,
]
\addplot [domain=-3:3, thick, black, smooth,<->,>=latex]{abs(x)};
\addplot [domain=-1.75:0, thick, black, smooth,<-,>=latex]{2*x^2};
\addplot [domain=0:2.5, thick, black, smooth,->,>=latex]{x^2};
\end{axis};
\path (current axis.south west) +(-0.5cm,-0.5cm) (current axis.north east) +(0.5cm,0.5cm);
\end{tikzpicture}
\end{document}
MWE 结果是