1

I need to mark three x values in a histogram. I thought a way would be introducing extra x ticks and customising major tick length and thickness so they show up more conspicuously. Is it possible to assign different length and thickness to each of them, and if so can I get some help with that?

Additionally, I would like each tick label to he different. When I introduce xticklabel if allocates the same label to all the extra ticks. How can I give each extra x tick a different label?

this is my code so far:

\documentclass[border=0.2mm]{standalone}
\usepackage{helvet}
\usepackage[eulergreek]{sansmath}
\usepackage{pgfplots}
\pgfplotsset{ compat=1.9, every axis/.style={axis on top}}
\usetikzlibrary{patterns}
\makeatletter

\begin{document}

\begin{tikzpicture} 
    \begin{axis}[ybar,
    width=7.5cm,
    ymax=10,
    xmax=3,    
    xticklabel style = {font=\sansmath\sffamily},
    yticklabel style = {font=\sansmath\sffamily},
    xtick pos=left,
    ytick pos=left,
    extra x ticks = {1.10,1.38,1.62},
    extra x tick style={
    xticklabel={\footnotesize SC},
    xticklabel style={above, rotate=45,ultra thick,yshift=65, xshift=75},
    tick align=inside,
    major tick length=95},      
    every axis label = {font=\sansmath\sffamily},
    xlabel={xxxx},
    ylabel={yyyy},
    legend style = {anchor=north east, 
                   nodes={scale=0.75,transform shape},
                   font=\sansmath\sffamily},
    label style = {font=\sansmath\sffamily},    
    enlarge y limits=-0.5,
    ]             
    \addplot+[hist={data=x,bins=9,data max=2,data min=-2.6},black!30, fill=black!30]
            table [y expr=1] {

2
0.5
2
-1.2
-0.3
-2
-1.55
0.2
-0.1
-1.4
1.1
-2
-2
-1
-2
0.5
1.7
2
0.33
-2
0.22
-2
-1
-1
0.2
1
2
-1
1.1
2
-1.3
-1.22
-2
0.33
0.22
1
0.1          
            };
            \addlegendimage{empty legend},
\addlegendentry{aaaa},
\end{axis}
\end{tikzpicture}
\end{document}

This would be what I would like to achieve:

enter image description here

Thank you in advance for the help!

1

I would just add them "by hand", i.e. using a loop.

\documentclass[border=0.2mm]{standalone}
\usepackage{helvet}
\usepackage[eulergreek]{sansmath}
\usepackage{pgfplots}
\pgfplotsset{ compat=1.9, every axis/.style={axis on top}}
\usetikzlibrary{patterns}
\makeatletter

\begin{document}

\begin{tikzpicture} 
    \begin{axis}[ybar,
    width=7.5cm,
    ymax=10,
    xmax=3,    
    xticklabel style = {font=\sansmath\sffamily},
    yticklabel style = {font=\sansmath\sffamily},
    xtick pos=left,
    ytick pos=left,
    every axis label = {font=\sansmath\sffamily},
    xlabel={xxxx},
    ylabel={yyyy},
    legend style = {anchor=north east, 
                   nodes={scale=0.75,transform shape},
                   font=\sansmath\sffamily},
    label style = {font=\sansmath\sffamily},    
    enlarge y limits=-0.5,
    ]             
    \addplot+[hist={data=x,bins=9,data max=2,data min=-2.6},black!30, fill=black!30]
            table [y expr=1] {

2
0.5
2
-1.2
-0.3
-2
-1.55
0.2
-0.1
-1.4
1.1
-2
-2
-1
-2
0.5
1.7
2
0.33
-2
0.22
-2
-1
-1
0.2
1
2
-1
1.1
2
-1.3
-1.22
-2
0.33
0.22
1
0.1          
            };
            \addlegendimage{empty legend},
\addlegendentry{aaaa},
\foreach \X [count=\Y] in {1.10,1.38,1.62}
{\edef\temp{\noexpand\draw[ultra thick] (axis cs:\X,0) -- (axis cs:\X,8.8-\Y) node[anchor=south
west,xshift=-2ex,font=\noexpand\sffamily]{label \Y} ;}
\temp} % axis cs: is not needed for pgfplots compat=1.11 or higher
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

1
  • As always, perfect answers. Thank you so much!
    – Emmo03
    Jan 30 '20 at 4:34

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.