I am trying to produce a dot plot where the horizontal axis represents probability.

At the moment, running the following code generates a very squashed dot plot, like the image in the screenshot.

How would you modify this code so that the horizontal axis stretches, with appropriate labels (0.1, 0.2, ...,0.9, 1) ?

Thank you.


\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);
  • You are loading pgfplots and its statistics library, but not using it at all. Why? If you use it, you can adjust the width with the pgfplots key width. – user194703 Aug 29 '19 at 22:50
  • E.g. \documentclass[]{article} \usepackage[margin=0.5in]{geometry} \usepackage{pgfplots} \pgfplotsset{compat=1.16,width=0.9\textwidth} \begin{document} \begin{center} \begin{tikzpicture} \begin{axis}[axis lines=left,ymin=0,ymax=2,hide y axis,xmin=0,xmax=1] \addplot[only marks,mark=*] coordinates {(0.5,0.5) (0.5,1.0) (0.5,1.5)}; \end{axis} \end{tikzpicture} \end{center} \end{document} – user194703 Aug 29 '19 at 22:55

As pure tikz solution, based on slightly modified your MWE:


\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] 
\foreach \i in {1,2,3}
\fill (5,\i) circle (2pt);

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.