我想画一条垂直虚线 (1,0) – (1,3) 但是不起作用..
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{pgfplots}
\usepackage[utf8]{inputenc}
\pgfplotsset{width=7cm,compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=center,
axis y line=center,
xlabel = {$\alpha$},
ylabel = {$h(\alpha)$},
xlabel style={ right},
ylabel style={above },
]
\addplot [
domain=-1.5:1.5,
samples=1000,
color=blue,
]
{1*x + 1*x^2};
\end{axis}
\draw[dashed] (1,0) -- (1,3);
\end{tikzpicture}
\end{document}
答案1
使用最近的 LaTeX 安装和最新版本pgfplots
包(你的版本很旧,是时候升级它了):
\documentclass{article}
\usepackage{pgfplots} % it loads tikz too
\usetikzlibrary{arrows}
\pgfplotsset{width=7cm,compat=1.17} % <----
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
xlabel = {$\alpha$},
ylabel = {$h(\alpha)$},
xlabel style={ right},
ylabel style={above },
]
\addplot +[domain=-1.5:1.5, samples=100, thick, no marks]
{1*x + 1*x^2};
\draw[dashed] (1,0) -- (1,3); % <---
\end{axis}
\end{tikzpicture}
\end{document}
答案2
将其放入环境中axis
:
\draw [dotted,->] (axis cs:1,0) -- (axis cs:1,3);