1

How could one draw the following using TikZ?

enter image description here

Many thanks!

2

See, if the following modification of Bobyandbob answer fulfill your expectations:

  \documentclass[tikz, border=3mm]{standalone}

    \begin{document}
    \begin{tikzpicture}[
dot/.style = {circle, fill=black,inner sep=0pt, minimum size=4pt},
every label/.append style = {inner sep=0pt, rotate around={45:(-0.5,1.5)}},
    thick      
                        ]
\draw ( 0,0.2) -- + (0,-0.4) node[below] {HIGH};
\draw (10,0.2) -- + (0,-0.4) node[below] {LOW};
%
\draw[thick] (0,0) -- node[below=2mm] {X axis titel} + (10,0);
%
\foreach \p in {0.1, 0.2, 0.5, 0.9}
{
    \node[dot,label={Example $=\p$}] at (10*\p,0) {};
}
\end{tikzpicture}
\end{document} 

enter image description here

Addendum:

in case, that labels have different widths, the rotation pivot is necessary calculate for each label separately. Determination of the pivot coordinate is done in two steps: in the first is measured length of label and in the second is calculated necessary displacement (offset) of rotating pivot from node coordinates:

\documentclass[tikz, border=3mm]{standalone}
\newlength\LabelWidth

\begin{document}
    \begin{tikzpicture}[
set text to width of/.code = {% code for the label length measurement
    \pgfmathsetlength\LabelWidth{width("#1")}%
    \pgfkeysalso{text width=\the\LabelWidth}% define label text width
                              },
dot/.style = {circle, fill=black, inner sep=0pt, minimum size=4pt,
              label={[set text to width of=#1, 
                      shift={(0.707*\LabelWidth/2+1em,0.707*\LabelWidth/2)},
                      rotate=45,
                      inner sep=0pt,
                      ]above:{#1}
                     },
              },
    thick
                        ]
\draw ( 0,0.2) -- + (0,-0.4) node[below] {HIGH};
\draw (10,0.2) -- + (0,-0.4) node[below] {LOW};
%
\draw[thick] (0,0) -- node[below=2mm] {X axis titel} + (10,0);
%
\foreach \p in {0.1, 0.222222222, 0.55, 0.9}
{   
    \node[dot=Example {$=\p$}] at (10*\p,0) {};
}
\end{tikzpicture}
\end{document}

Note: calculation of pivot offset had to consider rotation angle: in x direction is ~ \cos(angle) and in y direction ~ \sin(angle).

enter image description here

  • Neat code! The only problem is that if text labels are of different sizes then they cease to be aligned (e.g., "Example x=0.1" and "Example x=0.222222222"). Any way to align them to the bottom? – scaramouche Mar 3 '17 at 2:11
  • @scaramouche, i suspect, that this would be a case ... see addendum to my answer. – Zarko Mar 3 '17 at 3:56
  • this works, many thanks. Not sure, though, why it's necessary to include trigonometry inside the code, and not just say "anchor=south west" or something like that in the label style. (I tried, though, and Tikz didn't oblige). Tikz is the most convoluted language I'm aware of! – scaramouche Mar 3 '17 at 13:59
  • 1
    Anchor for rotating is in the middle of node, not at anchor of node. consequently you need to displaced node center such, that the after rotation it beginning is on the same distance dot. For this a some geometry calculation is necessary :-). Do you intend to accept one of received answers? – Zarko Mar 3 '17 at 14:12
3

Here a simple try:

You can controlle positioning with... distance=<lenght> and the change oft the angle 75: to 90,...Or something else.... Also with... anchor=south,xshift=1cm,yshift=-1cm...

enter image description here

 \documentclass[tikz, border=30pt]{standalone}
    \usepackage{tikz}
    \begin{document}
    \begin{tikzpicture}[scale=6]
\draw[thick] (1.1,0.05)--(1.1,-0.05) node[anchor=north] {HIGH};
\draw[thick] (0,0.05)--(0,-0.05) node[anchor=north] {LOW};

\node [draw=none] at (0.5,-0.1) {X axis titel} ;

\draw[thick] (0,0)--(1.1,0);


\foreach \Point in {0.1, 0.2, 0.5, 0.9}{
    \node[label={[label distance=1mm]75:\rotatebox{45}{Example x= \Point}}] at (\Point,0) {\textbullet};
}
\end{tikzpicture}
\end{document}
  • This is very nice. How can I control the position of the labels so that they appear just above the dots? (as in the example). Many thanks. – scaramouche Mar 2 '17 at 20:28
  • You can minimize the 'Label distance' and set 75: to 90: that equals positioning above. – Bobyandbob Mar 2 '17 at 20:33
  • If I use "90:" the labels jump to the left of the points. – scaramouche Mar 2 '17 at 20:36
  • Add:\node[label={[label distance=0mm,anchor=south,xshift=0.8cm,yshift=-.2cm]90:\rotatebox{45}{ – Bobyandbob Mar 2 '17 at 20:51
  • Great, it worked! One last question: if you zoom in, you'll see that the bullet is not perfectly centered with respect to the horizontal line. Can it be centered? – scaramouche Mar 2 '17 at 21:15

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.