Как обозначить ось X?

Как обозначить ось X?

Вопрос: Я пытаюсь нарисовать два графика, на которых я хочу обозначить идеальную положительную корреляцию по оси x на первом графике и идеальную отрицательную корреляцию на втором графике.

МВЭ:

\documentclass{article}
\usepackage[a4paper,top=0.6in,bottom=0.3in,left=0.5in,right=0.5in,headheight=14.5pt]{geometry}
\usepackage{blindtext}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[utf8]{inputenc}
\usepackage[misc]{ifsym}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{forest}
\usepackage{tikz}
\usepackage{parskip}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}[domain = 0:5]
\draw[<->] (-1,0) -- (5.5,0) node[right] {$x$};
\draw[<->] (0,-1) -- (0,5.5) node[right] {$y$};
\draw[color = blue, thick] (1,1) -- (2,2) -- (3,3) -- (4,4) -- (5,5);
\fill (1,1)  circle[radius=2pt];
\fill (2,2)  circle[radius=2pt];
\fill (3,3)  circle[radius=2pt];
\fill (4,4)  circle[radius=2pt];
\fill (5,5)  circle[radius=2pt];
\end{tikzpicture}\qquad\qquad\qquad\qquad
\begin{tikzpicture}[domain = 0:5]
\draw[<->] (-1,0) -- (5.5,0) node[right] {$x$};
\draw[<->] (0,-1) -- (0,5.5) node[right] {$y$};
\draw[color = blue, thick] (1,5) -- (2,4) -- (3,3) -- (4,2) -- (5,1);
\fill (1,5)  circle[radius=2pt];
\fill (2,4)  circle[radius=2pt];
\fill (3,3)  circle[radius=2pt];
\fill (4,2)  circle[radius=2pt];
\fill (5,1)  circle[radius=2pt];
\end{tikzpicture}
\end{document}

решение1

Просто добавьте второй узел при рисовании оси X. pos=0.6Это означает, что он будет размещен сразу после средней точки пути (0 — начало, 1 — конец).

\draw[<->] (-1,0) -- (5.5,0) node[right] {$x$} node[pos=0.6,below=3mm] {Perfect positive correlation};

Если вам интересно, вы можете сделать код намного короче, используя \draw plot, как в следующем примере:

\documentclass{article}
\usepackage[a4paper,top=0.6in,bottom=0.3in,left=0.5in,right=0.5in,headheight=14.5pt]{geometry}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
   % domain and samples applies to the plot commands below
   domain = 1:5,samples=5
   ]

\draw[<->] (-1,0) -- (5.5,0) node[right] {$x$} node[pos=0.6,below=3mm] {Perfect positive correlation};
\draw[<->] (0,-1) -- (0,5.5) node[right] {$y$};
\draw[color = blue, thick, mark=*]  plot(\x,\x);

\begin{scope}[xshift=8cm]
\draw[<->] (-1,0) -- (5.5,0) node[right] {$x$} node[pos=0.6,below=3mm] {Perfect negative correlation};
\draw[<->] (0,-1) -- (0,5.5) node[right] {$y$};
\draw[color = blue, thick, mark=*]  plot(\x,-\x+6);
\end{scope}
\end{tikzpicture}
\end{document}

Связанный контент