0

I created a bar graph, but struggle in added in Data Table, Error bar, Grid line.

enter image description here

\documentclass[tikz,border={10pt 20pt 5pt 5pt}]{standalone}


\usepackage{pgfplots}
\pgfplotsset{compat=1.16}   % <---

\begin{document}

 \begin{tikzpicture}
    \pgfplotstableread{
interval  carT  carD
    1    68    32
    2    12.8   3.8
    3    15.5    10.4
    4    14.0    17.3
    5    7.9    21.3
    6   68    32
    7    68   32
    8    68   32
    9    68   32
   10    68   32
        }\mydata

    \begin{axis}[
    width=\linewidth,
    height=.8\linewidth,
    ybar=0.5mm,         % <--- distance between bars (shift bar)
    bar width=4.4mm,    % <--- width of bars
    legend style={legend columns=-1,
      outer sep=1mm,    % <---
      font=\scriptsize, % <---
      anchor=north,
      at={(0.5,1)},
                  },
    nodes near coords,
    nodes near coords style={font=\scriptsize, inner sep=2pt}, % <---
    nodes near coords align={vertical},
    ylabel={\%},
    xlabel={X-axis},
    ymin=0, ymax=100,     % <---              
    xtick=data,
    scale only axis,     % <---
        ]
    \addplot table[x=interval,y=carT]{\mydata};
    \addplot table[x=interval,y=carD]{\mydata};
    \legend{Trips, Distance}
    \end{axis}
\end{tikzpicture}


\end{document}
aan
  • 2,663
  • Could you elaborate what is the difference to your previous question? – Stefan Pinnow Aug 27 '19 at 13:48
  • @StefanPinnow, deleted my previous questions – aan Aug 27 '19 at 13:58
  • So far it is unclear how you determine the error bars. Is that a fixed (absolute/relative) value or is it individual for each bar? In the latter case, please add the error values to the data table. Then I guess we are able to help you. – Stefan Pinnow Aug 27 '19 at 14:00
  • @StefanPinnow. Because I used Excel, I am able to add Chat Element, and then Error Bar and then Percentage. Each test are total of 100% – aan Aug 27 '19 at 14:09
  • @StefanPinnow, code not reproduce showed image. Image serve only as illustration, where OP like to have table below of diagram (instead of tick and ticklabels) produced by provided code. However content of table is not known (seems can be any). On that way i understand this question. – Zarko Aug 27 '19 at 14:18
  • Regarding the last two questions add e.g. ymajorgrids=true,error bars/y dir=both,error bars/y fixed relative=0.1 to the axis options. – Stefan Pinnow Aug 27 '19 at 14:50
  • Regarding the first question I guess its a duplicate. Have a look at e.g. https://tex.stackexchange.com/a/401898/95441 or https://tex.stackexchange.com/a/371573/95441. – Stefan Pinnow Aug 27 '19 at 14:51

0 Answers0