轴值较小的点图

轴值较小的点图

我正在尝试制作一个点图,其中横轴代表概率。

目前,运行以下代码会生成一个非常扁平的点图,就像屏幕截图中的图像一样。

如何修改此代码,以便水平轴拉伸,并带有适当的标签(0.1、0.2、...、0.9、1)?

谢谢。

输出

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\usepackage{mathtools}
\usepgfplotslibrary{statistics}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
\begin{center}
\begin{tikzpicture}[x={(1.5,0)}]
\draw[latex-latex] (0,0) -- (1,0);
\foreach \x in  {0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0}
\draw[shift={(\x,0)},color=black] (0pt,1pt) -- (0pt,-1pt);
\foreach \x in {0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0}
\draw[shift={(\x,0)},color=black] (0pt,0pt) -- (0pt,-1pt) node[below] 
{$\pgfmathprintnumber[fixed,fixed zerofill,precision=1]{\x}$};
\draw[fill=black] (0.5,0.5) circle (2pt);
\draw[fill=black] (0.5,1.0) circle (2pt);
\draw[fill=black] (0.5,1.5) circle (2pt);
\end{tikzpicture}
\end{center}
\end{document}

答案1

作为纯tikz解决方案,基于稍微修改的 MWE:

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{tikz}

\begin{document}
    \begin{center}
\dimendef\mydimen=0                 % define new dimension name
\pgfmathsetlength{\mydimen}{+1.2cm} % define units used in `tikzpicture`
\begin{tikzpicture}[x=\mydimen, y=0.8\mydimen] % define ratio width/height
\draw[latex-latex] (0,0) -- (10,0);
\foreach \x [evaluate=\x as \xx using \x/10]  in {0,1,...,10}
\draw   (\x,2pt) -- ++ (0,-4pt) node[below, font=\scriptsize] 
    {$\pgfmathprintnumber[fixed,precision=1]{\xx}$};
%    
\foreach \i in {1,2,3}
\fill (5,\i) circle (2pt);
\end{tikzpicture}
    \end{center}
\end{document}

在此处输入图片描述

相关内容