1

I have a results of my research in the form of a bar chart created from excel work sheet. The image of my excel sheet and bar chart is given in the figure below;enter image description here
Please help me with code, I am new to latex and never draw these kind of bar charts earlier. Thanks in advance.

2
  • 1
    Search in forum. Many examples provided by experts can be found, for example: tex.stackexchange.com/a/126577/31034
    – user31034
    May 1, 2014 at 12:25
  • Open a terminal and type texdoc pgfplots. The PDF opening contains a lot of information. You will be able to do your above plot in very short time.
    – LaRiFaRi
    May 1, 2014 at 14:17

1 Answer 1

2

This is an attempt, where the data is read in via pgfplotstableread, since the data has two parallel axis label, a way to work around is to draw the plot twice and change the xticklabelon the second plot. Furthermore, this solution applies shadows.blur from tikzlibrary to have the shadow effects in order to mimic the shadow effect in the OP. the parameters x/yshift below can be changed to meet your need. As can be seen in the OP, the second labels were overlapped and this is improved by the width=15cm in the axis options, which can also be adjusted to meet one's need.

blur shadow={shadow yshift=0pt, shadow xshift=2pt}

enter image description here

Code:

\documentclass[border=10pt]{standalone}
\usepackage{pgf,pgfplots}
\usepackage{tikz,pgfplotstable}
\pgfplotsset{compat=1.8}
\usetikzlibrary{arrows,automata,calc,shapes, positioning,shadows,shadows.blur,shapes.geometric}
\begin{document}
\definecolor{darkblue}{HTML}{003366}
\def\mystrut{\vphantom{pb}}

\pgfplotstableread[col sep=comma]{
items,section_1,section_2
max,centroid,82
max,bisector,82
max,mom,84
max,lom,84
max,som,71
sum,centroid,82
sum,bisector,82
sum,mom,80
sum,lom,79
sum,som,71
prob,centroid,82
prob,bisector,82
prob,mom,80
prob,lom,79
prob,som,71
}\datatable

\begin{tikzpicture}
\begin{axis}[ybar=2pt, bar width=10pt,
    height=5cm, width=15cm,
    enlarge y limits=false,
    ymin=64, ymax=85,
    xtick=data,
xticklabels from table={\datatable}{section_1}, 
x tick label style={rotate=90, xshift=-1cm,yshift=-0.2cm, anchor=south,font=\small,align=center},
]
\addplot +[draw opacity=0, fill=darkblue,
blur shadow={shadow yshift=0pt, shadow xshift=2pt}]
table[x expr=\coordindex, y=section_2, ] {\datatable}; 
\end{axis}

\begin{axis}[ybar=2pt, bar width=10pt,
    height=5cm, width=15cm,
    enlarge y limits=false,
    ymin=64,  ymax=85,
    xtick=data,
    xticklabels from table={\datatable}{items}, 
    x tick label style={yshift=-2.2cm,anchor=south,font=\mystrut,align=center}, 
]
\addplot +[draw opacity=0, fill=darkblue,
blur shadow={shadow yshift=0pt, shadow xshift=2pt}]
table[x expr=\coordindex, y=section_2, ] {\datatable}; 
\end{axis}
\end{tikzpicture}%
\end{document}
2
  • I draw this chart bar but the background only in bars is black, how can I set this ?
    – cst
    May 1, 2014 at 14:54
  • 1
    OK, you need to copy this file and put it into your current directory tikzlibraryshadows.blur.code.tex - TeXdoc.net. I used this keyword shadow.blur, latex search in the internet. Use pdflatex to compile.
    – Jesse
    May 1, 2014 at 15:06

You must log in to answer this question.

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