1

I would like to set the dimension of a square in the legend and then be able to set the same distance between xticks and yticks being the length of that square.

\documentclass{report}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
        \begin{axis}[ybar,ytick=data,ymajorgrids=true,yminorgrids=true,
        ymin=0,ymax=6.2,xmax=2250,xtick=data,
        area style,axis x line=bottom,
        axis y line = none,
        xlabel=\texttt{Salaire},ylabel=\texttt{Effectif},
        legend style={at={(1,0.5)},draw=none},
           /pgf/number format/.cd,    
        use comma,
        1000 sep={},
        legend image code/.code={%
            \draw[#1, draw] (0cm,-0.5cm) rectangle ++ (1cm,1cm);}
        ]
        \addplot+[ybar interval,mark=no] plot coordinates { (1400, 2) (1500, 5) (1600, 4) (1700, 3) (1800, 1) (2200,1)  };
        \legend{\texttt{20 employés}}
        \end{axis}
\end{tikzpicture}
\end{document}

Thank you

1 Answer 1

1

You could set the width of your bar using bar width (and delete ybar interval). In your case set bar width=1cm.

(I scaled the graph and change the x limit to avoid overlapping of bars)

\begin{tikzpicture}
\begin{axis}[
scale=2,
ybar,
ytick=data,
ymajorgrids=true,
yminorgrids=true,
ymin=0,
ymax=6.2,
xmin=1300,
xmax=2300,
xtick=data,
area style,
axis x line=bottom,
axis y line = none,
xlabel=\texttt{Salaire},
ylabel=\texttt{Effectif},
legend style={at={(1,0.5)},draw=none},
/pgf/number format/.cd,    
use comma,
1000 sep={},
legend image code/.code={%
\draw[#1, draw] (0cm,-0.5cm) rectangle ++ (1cm,1cm);}
]
\addplot+[mark=no, bar width=1cm] plot coordinates { (1400, 2) (1500, 5) (1600, 4) (1700, 3) (1800, 1)  (2200, 1) };


\legend{\texttt{20 employés}}

\end{axis}
\end{tikzpicture}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .