我有 40 个观察结果,如何绘制一条水平线来适应所有这些观察结果我的代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{tikz}
\begin{document}
\begin{figure}[H]
\begin{center}
\begin{tikzpicture}[scale=2.7]
\begin{scope} [thin]
\draw[latex-] (4,0) -- (10,0) ;
\foreach \x in {4.71,5.01,5.04,5.60,5.78,6.43,6.53,6.84,6.91,6.96,7,7.21,7.22,7.24,77.25,7.35,7.55,7.58,7.62,7.69,7.98,7.99,8.04,8.08,8.12,8.18,8.20,8.26,8.27,8.34,8.62,8.66,8.91,8.94,8.97,9.03,9.05,9.16}
\draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt);
\foreach \x in {4.71,5.01,5.04,5.60,5.78,6.43,6.53,6.84,6.91,6.96,7,7.21,7.22,7.24,77.25,7.35,7.55,7.58,7.62,7.69,7.98,7.99,8.04,8.08,8.12,8.18,8.20,8.26,8.27,8.34,8.62,8.66,8.91,8.94,8.97,9.03,9.05,9.16}
\draw[shift={(\x,0)},color=black] (0pt,0pt) -- (0pt,-3pt) node[below]
{$\x$};
\draw[dashed] (4,1) -- (10,1) ;
\filldraw[black] (5.01,1) circle (1pt) ;
\filldraw[black] (5.04,1) circle (1pt) ;
\filldraw[black] (5.60,1) circle (1pt) ;
\filldraw[black] (5.78,1) circle (1pt) ;
\filldraw[black] (6.43,1) circle (1pt) ;
\filldraw[black] (6.53,1) circle (1pt) ;
\filldraw[black] (6.96,1) circle (1pt) ;
\filldraw[black] (7,1) circle (1pt) ;
\filldraw[black] (7.21,1) circle (1pt) ;
\filldraw[black] (7.58,1) circle (1pt) ;
\filldraw[black] (8.12,1) circle (1pt) ;
\filldraw[black] (8.26,1) circle (1pt) ;
\filldraw[black] (8.27,1) circle (1pt) ;
\filldraw[black] (8.34,1) circle (1pt) ;
\filldraw[black] (8.62,1) circle (1pt) ;
\filldraw[black] (8.66,1) circle (1pt) ;
\filldraw[black] (8.91,1) circle (1pt) ;
\filldraw[black] (8.94,1) circle (1pt) ;
\filldraw[black] (9.05,1) circle (1pt) ;
\filldraw[black] (9.16,1) circle (1pt) ;
\node [above] at (4,1) {$x\{1\}$};
\draw[dashed] (4,2) -- (10,2) ;
\filldraw[black] (6.84,2) circle (0.5pt) ;
\filldraw[black] (6.91,2) circle (0.5pt) ;
\filldraw[black] (7.22,2) circle (0.5pt) ;
\filldraw[black] (7.24,2) circle (0.5pt) ;
\filldraw[black] (7.25,2) circle (0.5pt) ;
\filldraw[black] (7.35,2) circle (0.5pt) ;
\filldraw[black] (7.55,2) circle (0.5pt) ;
\filldraw[black] (7.62,2) circle (0.5pt) ;
\filldraw[black] (7.69,2) circle (0.5pt) ;
\filldraw[black] (7.98,2) circle (0.5pt) ;
\filldraw[black] (7.99,2) circle (0.5pt) ;
\filldraw[black] (8.04,2) circle (0.5pt) ;
\filldraw[black] (8.08,2) circle (0.5pt) ;
\filldraw[black] (8.18,2) circle (0.5pt) ;
\filldraw[black] (8.97,2) circle (0.5pt) ;
\node [above] at (4,2) {$x\{3\}$};
\draw[dashed] (4,3) -- (10,3) ;
\filldraw[black] (4.71,3) circle (1pt) ;
\filldraw[black] (8.20,3) circle (1pt) ;
\filldraw[black] (9.03,3) circle (1pt) ;
\node [above] at (4,3) {$x\{4\}$};
\end{scope}
\end{tikzpicture}
\end{center}
\caption{Dataset for example}
\end{figure}
\end{document}
答案1
您的基线是 6 厘米,您将其放大了 2.7 倍,因此您的绘图宽度大约为 16 厘米,这对于大多数标准设置的文本宽度来说太大了。
您可以使用类似以下方法更改文档的几何形状
\usepackage[textwidth=17cm]{geometry}
或缩小绘图,或使用
\usepackage{rotating}
....
\begin{sideways}
...
\end{sideways}
\documentclass{article}
%\usepackage[textwidth=17cm]{geometry}
\usepackage{tikz}
\usepackage{rotating}
\begin{document}
%\centering
\begin{sideways}
\begin{tikzpicture}[
scale=2.7,
label/.style={right,rotate=-90,font=\tiny}
]
\begin{scope} [thin]
\draw[latex-] (4,0) -- (10,0) ;
\draw[dashed] (4,1) node[above]{$x\{1\}$} -- (10,1);
\foreach \x in {5.01,5.04,5.60,5.78,6.43,%
6.53,6.96,7,7.21,7.58,8.12,8.26,%
8.27,8.34,8.62,8.66,8.91,8.94,9.05,9.16} {
\filldraw (\x,1) circle (1pt);
\draw (\x,3pt) -- (\x,-3pt) node[label]{$\x$};
}
\draw[dashed] (4,2) node[above]{$x\{3\}$} -- (10,2);
\foreach \x in {6.84,6.91,7.22,7.24,7.25,%
7.35,7.55,7.62,7.69,7.98,7.99,8.04,%
8.08,8.18,8.97} {
\filldraw (\x,2) circle (0.5pt);
\draw (\x,3pt) -- (\x,-3pt) node[label]{$\x$};
}
\draw[dashed] (4,3) node[above]{$x\{4\}$} -- (10,3);
\foreach \x in {4.71,8.20,9.03} {
\filldraw (\x,3) circle (1pt);
\draw (\x,3pt) -- (\x,-3pt) node[label]{$\x$};
}
\end{scope}
\end{tikzpicture}
\end{sideways}
\end{document}