我想使用 pgfplots 在X
轴和函数之间绘制一个角度2x-3
(带箭头)。
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{quotes, angles}
\pgfplotsset{compat = 1}
\begin{document}
\begin{tikzpicture}
\coordinate (origin) at (0,0);
\coordinate (xmin) at (-1, 0);
\coordinate (xmax) at (4, 0);
\coordinate (ymin) at (0, -4);
\coordinate (ymax) at (0, 4);
\coordinate (node1) at (0, -3);
\coordinate (node2) at (2, 0);
\coordinate (node3) at (1.5, 0);
\coordinate (node4) at (2, 1);
% draw axes
\fill[black] (node1) circle (0.06) node[black, left] {$-3$};
\draw[thick, gray, ->] (xmin) -- (xmax) node[black, above] {$x$};
\draw[thick, gray, ->] (ymin) -- (ymax) node[black, right] {$y$};
\draw[scale = 1, <->, domain = -0.5:3, smooth, variable = \x, blue] plot ({\x}, {2*\x - 3});
\draw (node2) arc [<->, text = red, draw = orange, angle eccentricity = 1.2, start angle = 0, end angle = 60, radius = 0.5cm] node[blue, right] {$60$};
\pic [my angle = 19mm/1.15, "$60\degree$",red, right] {angle = node2--node3--node4};
\end{tikzpicture}
\end{document}
有没有办法用 pgfplots 来做到这一点?
答案1
和pgfplots
:
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{angles, arrows.meta,
quotes}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}[
> = Straight Barb,
my angle/.style args = {#1/#2}{draw,<->,
angle radius=#1,
angle eccentricity=#2,
%anchor=south west,
}, % angle label position!
dot/.style = {circle, fill, inner sep=-1.2pt}
]
\begin{axis}[
axis lines=middle,
xmin=-0.5, xmax=4, xtick=\empty,
ymin=-2, ymax=5, ytick=\empty,
xlabel=$x$,
ylabel=$y$,
xlabel style={anchor=west},
ylabel style={anchor=south},
no marks,
samples=2
]
\addplot +[domain=-1:4, thick] {2*\x-1} coordinate (A);
\coordinate (B) at (0.5,0); % calculated from arrow function
\coordinate (C) at (4,0);
\node[dot, label=left:$-1$] at (0,-1) {};
\pic [my angle=9mm/1.4, "\qty{30}{\degree}"] {angle = C--B--A};
\end{axis}
\end{tikzpicture}
\end{document}
和tikz
:
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{angles, arrows.meta,
quotes}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}[
> = Straight Barb,
my angle/.style args = {#1/#2}{draw,<->,
angle radius=#1,
angle eccentricity=#2,
},
dot/.style = {circle, fill, inner sep=-1.2pt}
]
\draw[->,red] (-1,0) -- (4,0) coordinate[label=right:$x$] (A);
\draw[->] (0,-2) -- (0,5) node[above] {$y$};
\coordinate (B) at (0.5,0);
\coordinate (C) at (4,0);
\draw[blue, thick] plot[domain=-0.5:3, samples=100] (\x,2*\x-1) coordinate (A);
\node[dot, label=left:$-1$] at (0,-1) {};
\pic [my angle=9mm/1.4, "\qty{30}{\degree}"] {angle = C--B--A};
\end{tikzpicture}
\end{document}
答案2
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles, quotes}
\begin{document}
\begin{tikzpicture}
\draw[->] (-2,0)--(4,0) node[right] {$x$};
\draw[->] (0,-4)--(0,4) node[above] {$y$};
\coordinate (A) at (1.5,0);
\coordinate (B) at (2,0);
\coordinate (C) at (2,1);
\draw[domain=-0.5:2.5, <->] plot(\x, 2*\x-3);
\draw pic [draw, angle radius = 0.5cm, angle eccentricity = 1.5,"$\alpha$"] {angle=B--A--C};
\end{tikzpicture}
\end{document}