1

I want to draw a bar chart with x axis label empty and the color of the filling reflecting the axis label from legend. Similar to this one here. enter image description here

My code is as follows:

\documentclass[12pt, a4paper, titlepage]{scrartcl}

\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\graphicspath{{./Figures/}}

\usepackage{url}
%\usepackage{titlesec}
%\newcommand{\sectionbreak}{\clearpage}
\usepackage{dirtree}
\usepackage{color}
\usepackage{listings}
\usepackage{caption}
\usepackage{pdfpages}
\usepackage{pgfplots}
\newcommand{\courierword}[1]{\textsf{\itshape #1}}{\fontfamily{pcr}\selectfont}%
\setlength{\parindent}{0.0cm}
\setlength{\parskip}{1ex}

\setkomafont{sectioning}{\normalcolor\bfseries}


\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ylabel=Time(s),
]
\addplot[ybar]
    coordinates{(Make Clean,14)};
\addplot[ybar]
    coordinates{(Gradle Clean,16)};
\legend{Make Clean, Gradle Clean}
\end{axis}
\end{tikzpicture}

\end{document}
2
  • 1
    It would be nice if you could complete your code and make it compilable by including the 'documentclass' that you are using, as well as relevant packages.
    – Troy
    Mar 14 '17 at 15:13
  • It doesn't compile as of now. There are errors.
    – Müller
    Mar 14 '17 at 15:22
2

I am not sure if I understand what you want to do: \documentclass[margin=5pt]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.14}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ylabel=Time(s),
    ymin=0,
    xtick=\empty,
    enlarge x limits={abs=\pgfplotbarwidth/2},
    ybar=-\pgfplotbarwidth,% ybar must be -bar width
    x=\pgfplotbarwidth,
    bar width=30pt,
    legend style={
      cells={anchor=west},
      legend pos=outer north east,
    }
]
%
\addplot coordinates{(1,14)};
\addplot coordinates{(2,16)};
%
\addplot coordinates{(4,10)};
\addplot coordinates{(5,6)};
%
\legend{Make Clean,Gradle Clean,Test 1,Test 2}
\end{axis}
\end{tikzpicture}

\end{document}

results in

enter image description here

2
  • This is exactly how I wanted to do it. However, I want the bars to be grouped. Like, bars for Make Clean & Gradle Clean next to each other, then Test 1 and Test 2 next to each other.
    – Müller
    Mar 15 '17 at 8:21
  • 1
    I have added option x=\pgfplotbarwidth to get the bars next to each other.
    – esdd
    Mar 15 '17 at 18:50

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.