我需要帮助来调整这个组图。我设法解决了之前的问题,但现在我就像大海捞针。
1. 如何使条形变薄,以便它们更合适?
- 我尝试在两者上调整 (ybar= 0-10pt) + (2*\pfglinewidth)
- 我已经对我能找到的所有变量进行了调整……有些似乎没有任何区别(ybar)。
2. 如何调整各个框的宽度?
- 它们当然需要有相同的宽度,但似乎没有发现任何可以改变它的东西。调整一般宽度只会使整个“图像”更加扭曲。我当然想更好地适应这些条形图。
3. 如何使用这些代码设置添加误差线?
- 我最近成功使用了如下所示的误差线。但是,由于我的内联表位于代码中的不同位置,我可以传递相同的参数吗?
\addplot [draw=green,fill=green!25,error bars/.cd, y dir=both, y explicit] 坐标 { 带数据 xyz 的表格 } Blockquote
代码现在完全可编译。
\documentclass{article}
\usepackage{pgfplots,pgfplotstable}
\usepackage{changepage}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotsset{compat=1.12}
\pgfplotstableread{
Criterion Wasserverbrauch {CO$_2$-Emission}
Komp 8 2349
Komp+PV 8 452
Sorp 14 1006
ABC 230 1006
}\Rambo
\pgfplotstableread{
Criterion Wasserverbrauch {CO$_2$-Emission}
Komp 100 10220
Komp+PV 36 5891
Sorp 85 3160
ABC 45 3400
}\Godfather
\pgfplotstableread{
Criterion Wasserverbrauch {CO$_2$-Emission}
Komp 230 25657
Komp+PV 97 18306
Sorp 184 7461
ABC 240 7461
}\Jedi
\pgfplotstableread{
Criterion Wasserverbrauch {CO$_2$-Emission}
Komp 230 25657
Komp+PV 97 18306
Sorp 184 7461
ABC 240 7461
}\LordVader
\begin{document}
\begin{adjustwidth}{-13em}{1em}
\begin{tikzpicture}
\pgfplotsset{
water/.style={
fill=cyan,
draw=cyan!50!black
},
co2/.style={
fill=orange,
draw=orange!50!black
}
}
\begin{groupplot}[
group style={
columns=4,
group name=plots,
x descriptions at=edge bottom,
y descriptions at=edge left,
},
ylabel={[ML]}, ylabel style=cyan!50!black,
yticklabel style=cyan!50!black,
ybar = 0pt, /pgf/bar shift=-12pt, % We have to manually move the bars
ymin=0, ymax=270,
enlarge x limits={abs=.5},
width=0.45\textwidth,
height=0.6\textwidth,
xticklabels from table={\Rambo}{Criterion},
x tick label style={rotate=90,anchor=east},
xtick=data, xtick pos=left,
legend columns=2]
\nextgroupplot[xlabel=Rambo,legend to name=grouplegend]
\addplot [water] table [x expr=\coordindex,y index=1] {\Rambo};
\addlegendentry {Wasserverbrauch}%
\addlegendimage{co2,ybar legend}
\addlegendentry{CO$_2$-Emission}
\nextgroupplot[xlabel=Godfather]
\addplot [water] table [x expr=\coordindex,y index=1] {\Godfather};
\nextgroupplot[xlabel=Jedi]
\addplot [water] table [x expr=\coordindex,y index=1] {\Jedi};
\nextgroupplot[xlabel=LordVader]
\addplot [water] table [x expr=\coordindex,y index=1] {\LordVader};
\end{groupplot}
\begin{groupplot}
[group style= {
columns=4,
group name=plots,
y descriptions at=edge right,
},
ybar = 0pt, /pgf/bar shift=0pt,
ymin=0, ymax=2.7e4,
enlarge x limits={abs=.5},
width=0.45\textwidth,
height=0.6\textwidth,
xtick=\empty, axis line style=transparent,
ylabel={[kg CO$_2$ per year]},yticklabel style=orange!75!black,
ylabel style=orange!75!black]
\nextgroupplot[scaled y ticks=false]
\addplot [co2] table [x expr=\coordindex,y index=2] {\Rambo};
\nextgroupplot[scaled y ticks=false]
\addplot [co2] table [x expr=\coordindex,y index=2,
] {\Godfather};
\nextgroupplot[scaled y ticks=false]
\addplot [co2] table [x expr=\coordindex,y index=2,
] {\LordVader};
\nextgroupplot
\addplot [co2] table [x expr=\coordindex,y index=2] {\Jedi};
\end{groupplot}
\node at (plots c2r1.north) [anchor=south, yshift=.6cm] {\ref{grouplegend}};
\end{tikzpicture}
\end{adjustwidth}
\end{document}
答案1
由于您没有提供任何误差线数据 - 但无论如何您自己已经找到了解决方案 - 这里是剩余 2 个问题 1 和 2 的解决方案。
有关更多详细信息,请查看代码中的注释。
% used PGFPlots v1.14
%\documentclass[border=5pt]{standalone}
\documentclass[DIV=12]{scrartcl}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{
calc, % <-- to calculate the legend position
pgfplots.groupplots,
}
\pgfplotsset{
% use this `compat' level or higher to be able to provide (relative) axis
% units to `bar width' and `bar shift'
compat=1.7,
% define a style wich stores the stuff the both `groupplot' environments
% have in common
% (unfortunately there seems to be a bug that prevents also collecting
% the stuff from `group style' in another style, see
% <https://sourceforge.net/p/pgfplots/bugs/137/>
% that is why we have to provide it in both cases separately)
my axis style/.style={
% to easier estimate the `width' scale only the axis (box without the
% ticks and labels)
scale only axis,
% now play around with the value so that it fits the `\textwidth'
% (but of course it has to be smaller than 0.25, because there are
% 4 plots + 2x ticks + 2x axis labels + 3x axis seperation
width=0.17\textwidth,
height=0.4\textwidth,
enlarge x limits={abs=0.5},
ybar,
% to make the individual bars independent of the `width' of the
% surrounding axis give a `bar width' in axis units
/pgf/bar width=\BarWidth,
},
water/.style={
fill=cyan,
draw=cyan!50!black,
},
co2/.style={
fill=orange,
draw=orange!50!black,
},
}
\pgfplotstableread{
Criterion Wasserverbrauch {CO$_2$-Emission}
Komp 8 2349
Komp+PV 8 452
Sorp 14 1006
ABC 230 1006
}\Rambo
\pgfplotstableread{
Criterion Wasserverbrauch {CO$_2$-Emission}
Komp 100 10220
Komp+PV 36 5891
Sorp 85 3160
ABC 45 3400
}\Godfather
\pgfplotstableread{
Criterion Wasserverbrauch {CO$_2$-Emission}
Komp 230 25657
Komp+PV 97 18306
Sorp 184 7461
ABC 240 7461
}\Jedi
\pgfplotstableread{
Criterion Wasserverbrauch {CO$_2$-Emission}
Komp 230 25657
Komp+PV 97 18306
Sorp 184 7461
ABC 240 7461
}\LordVader
\begin{document}
\hrulefill
\begin{tikzpicture}
% define the values for the horizontal separation of the different axis
% environments, as well as the width and shift of the bars
\pgfmathsetlengthmacro{\HorSep}{5mm}
\pgfmathsetmacro{\BarWidth}{0.3}
\pgfmathsetmacro{\BarShift}{\BarWidth/2+0.05}
\begin{groupplot}[
my axis style,
%
group style={
group name=plots,
columns=4,
horizontal sep=\HorSep,
x descriptions at=edge bottom,
y descriptions at=edge left,
},
ylabel={[ML]},
ylabel style=cyan!50!black,
yticklabel style=cyan!50!black,
ymin=0,
ymax=270,
xticklabels from table={\Rambo}{Criterion},
x tick label style={rotate=90,anchor=east},
xtick=data,
xtick pos=left,
legend columns=2,
%
% % this doesn't seem to work ...
% every axis plot no 0/.append style={water},
% % ... and we cannot use this style here, because that would also
% % overwrite the `\addlegendimage' style
% % so we have to apply the style to each `\addplot' manually
% every axis plot post/.style={water},
table/x expr=\coordindex,
table/y index=1,
%
/pgf/bar shift=-\BarShift,
]
\nextgroupplot[
xlabel=Rambo,
legend to name=grouplegend,
legend entries={
Wasserverbrauch,
CO$_2$-Emission,
},
]
\addplot [water] table {\Rambo};
\addlegendimage{co2,ybar legend}
\nextgroupplot[xlabel=Godfather]
\addplot [water] table {\Godfather};
\nextgroupplot[xlabel=Jedi]
\addplot [water] table {\Jedi};
\nextgroupplot[xlabel=LordVader]
\addplot [water] table {\LordVader};
\end{groupplot}
\begin{groupplot}[
my axis style,
%
group style={
columns=4,
horizontal sep=\HorSep,
y descriptions at=edge right,
},
ymin=0,
ymax=2.7e4,
xtick=\empty,
axis line style=transparent,
ylabel={[kg CO$_2$ per year]},
yticklabel style=orange!75!black,
ylabel style=orange!75!black,
scaled y ticks=false,
%
every axis plot post/.style={co2},
table/x expr=\coordindex,
table/y index=2,
%
/pgf/bar shift=\BarShift,
]
\nextgroupplot
\addplot table {\Rambo};
\nextgroupplot
\addplot table {\Godfather};
\nextgroupplot
\addplot table {\LordVader};
\nextgroupplot[scaled y ticks=true]
\addplot table {\Jedi};
\end{groupplot}
\node [anchor=south, yshift=0mm] at
($ (plots c1r1.north west)!0.5!(plots c4r1.north east) $)
{\ref{grouplegend}};
\end{tikzpicture}
\end{document}