1

I need a vertical bar chart indicating the noise allowed levels. I wrote this MWE:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=1]
    \begin{axis}[
    ybar,
    xtick=data,
    ymin = 50,
    ymax = 75,
    xmin=0.5,
    xmax=3.5,
    ymajorgrids=true,
    bar width=0.5cm, 
    xlabel={Points},
    ylabel={Noise level \\ db(A)},  
    xlabel style={yshift=0cm},
    xtick align=inside,
    xticklabels={Point 1,Point 2,Point 3},
    nodes near coords,
    nodes near coords align={vertical},
    x tick label style={font=\normalsize, rotate=0, anchor=north}
    ]
    \addplot coordinates {(1,66) (2,64) (3,68)};

    \draw[dashed] (0,50) node[] {\footnotesize residential zone (single-family housing\\multi-family residential\\mobile homes)} -- (350, 50) ;
    \draw[red, dashed] (0,100) node {\footnotesize commercial zone (shops\\offices\\theaters\\restaurants)} -- (300, 100);
    \draw[dashed] (0,200) node {\footnotesize industrial zone (ship-building\\coal mining\\steel\\ceramics)} -- (300, 200);
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

How can I improve this code to obtain something like this:

enter image description here

1

Slightly different from image which you like to obtain:

enter image description here

MWE:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}[
    Levels/.style = {above right, font=\footnotesize, align=left}% <-- added
                    ]
    \begin{axis}[
    ybar,
    xtick=data,
    ymin = 50,
    ymax = 75,
    xmin=0.5,
    xmax=3.5,
    ymajorgrids=true,
    bar width=0.5cm,
    xlabel={Points},
    ylabel={Noise level \\ db (A)},
    ylabel style={yshift=-3mm},% <-- changed
    xtick align=inside,
    xticklabels={Point 1,Point 2,Point 3},
    nodes near coords,
    nodes near coords align={vertical},
    x tick label style={font=\normalsize, rotate=0, anchor=north},
    clip=false% <-- added
    ]
    \addplot coordinates {(1,66) (2,64) (3,68)};

\draw[dashed] (-250,50) node[Levels] % <-- changed coordinates (of all three lines)
    {residential zone (single-family\\
     housing, multi-family\\ 
     residential, mobile homes)}                -- +(550,0) ;
\draw[red, dashed] (-250,100) node[Levels]
    {commercial zone\\
     (shops offices,\\ theaters, restaurants)}  -- +(550,0);
\draw[dashed] (-250,200) node[Levels]
    {industrial zone (ship-building,\\
     coal mining, steel, ceramics)}             -- +(550,0);
\end{axis}
\end{tikzpicture}

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.