2

enter image description here

\documentclass{article} 
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc}

\begin{document}

\begin{figure} \begin{tikzpicture} \begin{axis} \draw[thick, dotted] (0,0) -- (1,1); \end{axis} \end{tikzpicture} \end{figure} \end{document}

\end{document}

Qrrbrbirlbel
  • 119,821
Tigas
  • 520
  • In short: you have to define the axis limits (if you don't insert any plots) with [xmin=0, xmax=1, ymin=0, ymax=1] and use (axis cs:0,0) -- (axis cs:1,1) (for older versions of pgfplots) or \pgfplotsset{compat=1.13}. – dexteritas Oct 20 '22 at 09:44
  • 1
    Welcome! ...you should have had a lot of warnings from pgfplots, about both the compatibility level and the null axis range. Never blindly ignore warnings... they are there for something! – Rmano Oct 20 '22 at 10:18

1 Answers1

2

Always set compat level when using PGFPlots. Do not use explicit axis cs: - it is default since level 1.11. To not have completely empty axis, set xmin, xmax, ymin and ymax or add a plot.

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0, xmax=1, ymin=0, ymax=1]
\draw[thick, dotted] (0,0) -- (1,1);
\end{axis}
\end{tikzpicture}
\end{document}

Empty graph with diagonal dotted line