4

I am studying this article: "Tufte-style Bar Charts with pgfplots". I was able to come up to step #4, and was stuck, removing the border from the bars:

\definecolor{tufte1}{rgb}{0.7,0.7,0.55}
\begin{tikzpicture}
...
  cycle list={
    fill=tufte1, draw=none\\
  }
...

I wrote this code:

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{pgfplots}
\begin{document}
%I added this
\definecolor{tufte1}{rgb}{0.7,0.7,0.55}
\begin{tikzpicture}
\begin{axis}[
  ybar,
  hide x axis,
  axis line style={opacity=0},
  major tick style={draw=none},
  ymin=0,
  bar width=0.9em,
  ymajorgrids,
  major grid style=white,
  axis on top
]
%and this
cycle list={
    fill=tufte1, draw=none\\
}
\addplot table {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}

data.csv:

1    8.5
2   12
3    6.5
4    7
5    3
6   17.5
7   13
8    8.5
9    6
10  11
11   5
12  10

But it doesn't work: the color is not changed, and the border stays intact:

enter image description here

How to remove the borders and change the color?

enter image description here

(I didn't narrow the bars - I don't like it).

  • Please add some example data to your MWE :-) – Joseph Wright Sep 7 '14 at 11:12
  • @JosephWright Added – user4035 Sep 7 '14 at 11:37
8

The cycle list key has to be added to the \begin{axis}[...] options, so it has to be within the square brackets:

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{pgfplots}
\begin{document}
\definecolor{tufte1}{rgb}{0.7,0.7,0.55}
\begin{tikzpicture}
\begin{axis}[
  ybar,
  hide x axis,
  axis line style={opacity=0},
  major tick style={draw=none},
  ymin=0,
  bar width=0.9em,
  ymajorgrids,
  major grid style=white,
  axis on top, % Don't close the square brackets here...
  cycle list={
    fill=tufte1, draw=none\\
  }
] % ... do it here
\addplot table {
1    8.5
2   12
3    6.5
4    7
5    3
6   17.5
7   13
8    8.5
9    6
10  11
11   5
12  10
};
\end{axis}
\end{tikzpicture}
\end{document}
|improve this answer|||||
4

Tufte-style bar charts are also easy to do in Metapost. Since plain Metapost is designed for drawing, and makes no assumptions about how to do charts, you get full control over where your "data ink" goes; but you do have to program everything from scratch. For something as simple as this sample chart (taken from The Visual Display of Quantitative Information ), the programming effort is minimal, but one should be wary of re-programming the whole of pgfplots for more complicated charts.

enter image description here

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);
% units (measured from my copy of VDQI, p.128)
u = 6cm/23;
v = 2.3mm;

% nice Tufte-like colour (although he uses grey in the original)
color olive; olive = (.7,.7,.55);

% draw the bars
x = 0;
hmax = 0;
for h=8.5,12,6.5,7,3,17.5,13,8.5,6,11,5,10:
  fill unitsquare xscaled u yscaled (v*h) shifted (x,0) withcolor olive;
  x := x+2u;
  if h>hmax: hmax:=h; fi
endfor

% draw and label the grid
for i=5 step 5 until hmax:
  draw (origin -- (23u,0)) shifted (0,i*v) withcolor background;
  label.lft((decimal i & "%") infont "pplr8r" scaled 0.7, (-3/4u,i*v));
endfor

% "Still, a thin baseline looks good:"
linecap := butt;
draw (origin -- (23u,0)) withcolor olive withpen pensquare scaled 0.8;
endfig;
end.

If you were doing lots of charts, you could consider writing a more general function to create them.

|improve this answer|||||

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.