我正在研究这篇文章:“”使用 pgfplots 绘制 Tufte 风格的条形图“。我能够进行到第 4 步,但遇到了问题,无法删除栏的边框:
\definecolor{tufte1}{rgb}{0.7,0.7,0.55}
\begin{tikzpicture}
...
cycle list={
fill=tufte1, draw=none\\
}
...
我写了这段代码:
\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}
数据.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
但它不起作用:颜色没有改变,边框保持完好:
如何去除边框并改变颜色?
(我没有缩小条形图——我不喜欢它)。
答案1
必须将键cycle list
添加到\begin{axis}[...]
选项中,因此它必须位于方括号内:
\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}
答案2
Tufte 风格的条形图也很容易制作元帖子。由于普通的 Metapost 是为绘图而设计的,并且不会对如何制作图表做出任何假设,因此您可以完全控制“数据墨水”的去向;但您必须从头开始编写所有程序。对于像这个示例图表这样简单的东西(取自量化信息的可视化展示pgfplots
),编程工作量很小,但应注意不要对更复杂的图表重新进行整个编程。
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.
如果您要制作大量图表,您可以考虑编写一个更通用的函数来创建它们。