我如何标记 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}

相关内容