von Hackysack » So 26. Apr 2020, 21:38
Hi!
Zuallererst: Ich bin ziemlicher LaTeX Noob, daher bitte ich um etwas Nachsicht
Ich versuche gerade, dieses Sample für mich zu adaptieren:
https://tex.stackexchange.com/questions ... 7660#37660
Ich würde gerne die Plots von den Säulendiagrammen auf Balkendiagramme ändern. Der erste Plot sieht noch gut aus, beim zweiten und dritten sind zuerst mal die Achsen nicht richtig skaliert und außerdem fliegen die Balken nur so durch die Gegend.
Mein Ziel: In jedem der Plots sollen die Reihenfolge der Daten gleich sein (zB. Grün immer als erster Eintrag) und die Achsen sollen in allen Plots automatisch skaliert werden - sie wie auch im ersten Plot.
Da ich nun schon einige Zeit investiert habe und einfach nicht weiterkomme, hoffe ich nun auf fachkundige Unterstützung
Minimales Sample/mein derzeitiger Stand:
https://www.overleaf.com/project/5ea5c8 ... 0001c01c2c
Und hier der Code nochmal direkt:
\documentclass{article}
\usepackage{lipsum}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=newest}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotstableread{
Criterion Rapperswil Palermo Jeddah
Turquoise 3620 15749 42754
Yellow 2739 15109 42240
Purple 3710 16146 40533
Red 714 9306 28919
Blue 2997 6840 11614
Orange 1589 4992 11786
Green 2122 11154 28747
}\datatable
% Retrieve the number of rows from the datatable
\pgfplotstablegetrowsof{\datatable}
\pgfmathsetmacro{\rows}{\pgfplotsretval-1}
\definecolor{RYB1}{RGB}{141, 211, 199}
\definecolor{RYB2}{RGB}{255, 255, 179}
\definecolor{RYB3}{RGB}{190, 186, 218}
\definecolor{RYB4}{RGB}{251, 128, 114}
\definecolor{RYB5}{RGB}{128, 177, 211}
\definecolor{RYB6}{RGB}{253, 180, 98}
\definecolor{RYB7}{RGB}{179, 222, 105}
\pgfplotscreateplotcyclelist{colorbrewer-RYB}{
{RYB1!50!black,fill=RYB1},
{RYB2!50!black,fill=RYB2},
{RYB3!50!black,fill=RYB3},
{RYB4!50!black,fill=RYB4},
{RYB5!50!black,fill=RYB5},
{RYB6!50!black,fill=RYB6},
{RYB7!50!black,fill=RYB7},
}
\pgfplotsset{
select row/.style={
x filter/.code={\ifnum\coordindex=#1\else\def\pgfmathresult{}\fi}
}
}
\begin{document}
All corresponding bars should be on the same position in each respective chart - green on top, turquoise on the bottom.
\begin{figure}[hbt!]
\centering
\begin{tikzpicture}
\begin{groupplot}
[
group style={
group size=2 by 2,
% columns=2,
% rows=2,
xlabels at=edge bottom,
ylabels at=edge left,
horizontal sep=0.05\textwidth, group name=plots
},
/pgf/number format/1000 sep={},
xbar,
xmin=0,
ytick={0,...,\rows},
yticklabels from table={\datatable}{Criterion},
xtick pos=bottom,
% y=0.1pt,
%
% ybar=0pt,
/pgf/bar shift=0pt,scale only axis,
width=\textwidth/3,
% yticklabel style={text width=0.035\textwidth, align=right, inner xsep=0pt, xshift=-0.005\textwidth},
% ylabel=kWh, ylabel style={text height=0.02\textwidth,inner ysep=0pt},
% enlarge x limits=0.15,
% ymin=0,
% xtick=\empty,
% tickpos=left,
% scaled y ticks=base 10:-3,
cycle list name=colorbrewer-RYB,
legend columns=-1,
legend style={draw=none, /tikz/every even column/.append style={column sep=5pt}},
legend image code/.code={%
\draw[#1] (0cm,-0.1cm) rectangle (0.3cm,0.1cm);
}
]
\nextgroupplot[xlabel=Rapperswil, legend to name=grouplegend,]
\pgfplotsinvokeforeach {0,...,\rows}{
\addplot table [ y expr=\coordindex, select row=#1, x=Rapperswil] {\datatable};
\addlegendentry {\pgfplotstablegetelem{#1}{Criterion}\of\datatable \pgfplotsretval}
}
\nextgroupplot[xlabel=Palermo]
\pgfplotsinvokeforeach {0,...,\rows}{
\addplot table [x expr=\coordindex, select row=#1, y=Palermo] {\datatable};
}
\nextgroupplot[xlabel=Jeddah]
\pgfplotsinvokeforeach {0,...,\rows}{
\addplot table [x expr=\coordindex, select row=#1, y=Jeddah] {\datatable};
}
\end{groupplot}
\end{tikzpicture}
\end{figure}
\end{document}
Vielen Dank schonmal!
Hi!
Zuallererst: Ich bin ziemlicher LaTeX Noob, daher bitte ich um etwas Nachsicht :)
Ich versuche gerade, dieses Sample für mich zu adaptieren: https://tex.stackexchange.com/questions/37568/colors-and-legend-in-groupplots-barplot/37660#37660
Ich würde gerne die Plots von den Säulendiagrammen auf Balkendiagramme ändern. Der erste Plot sieht noch gut aus, beim zweiten und dritten sind zuerst mal die Achsen nicht richtig skaliert und außerdem fliegen die Balken nur so durch die Gegend.
Mein Ziel: In jedem der Plots sollen die Reihenfolge der Daten gleich sein (zB. Grün immer als erster Eintrag) und die Achsen sollen in allen Plots automatisch skaliert werden - sie wie auch im ersten Plot.
Da ich nun schon einige Zeit investiert habe und einfach nicht weiterkomme, hoffe ich nun auf fachkundige Unterstützung :)
Minimales Sample/mein derzeitiger Stand: https://www.overleaf.com/project/5ea5c838f2c0540001c01c2c
Und hier der Code nochmal direkt:
[code]\documentclass{article}
\usepackage{lipsum}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=newest}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotstableread{
Criterion Rapperswil Palermo Jeddah
Turquoise 3620 15749 42754
Yellow 2739 15109 42240
Purple 3710 16146 40533
Red 714 9306 28919
Blue 2997 6840 11614
Orange 1589 4992 11786
Green 2122 11154 28747
}\datatable
% Retrieve the number of rows from the datatable
\pgfplotstablegetrowsof{\datatable}
\pgfmathsetmacro{\rows}{\pgfplotsretval-1}
\definecolor{RYB1}{RGB}{141, 211, 199}
\definecolor{RYB2}{RGB}{255, 255, 179}
\definecolor{RYB3}{RGB}{190, 186, 218}
\definecolor{RYB4}{RGB}{251, 128, 114}
\definecolor{RYB5}{RGB}{128, 177, 211}
\definecolor{RYB6}{RGB}{253, 180, 98}
\definecolor{RYB7}{RGB}{179, 222, 105}
\pgfplotscreateplotcyclelist{colorbrewer-RYB}{
{RYB1!50!black,fill=RYB1},
{RYB2!50!black,fill=RYB2},
{RYB3!50!black,fill=RYB3},
{RYB4!50!black,fill=RYB4},
{RYB5!50!black,fill=RYB5},
{RYB6!50!black,fill=RYB6},
{RYB7!50!black,fill=RYB7},
}
\pgfplotsset{
select row/.style={
x filter/.code={\ifnum\coordindex=#1\else\def\pgfmathresult{}\fi}
}
}
\begin{document}
All corresponding bars should be on the same position in each respective chart - green on top, turquoise on the bottom.
\begin{figure}[hbt!]
\centering
\begin{tikzpicture}
\begin{groupplot}
[
group style={
group size=2 by 2,
% columns=2,
% rows=2,
xlabels at=edge bottom,
ylabels at=edge left,
horizontal sep=0.05\textwidth, group name=plots
},
/pgf/number format/1000 sep={},
xbar,
xmin=0,
ytick={0,...,\rows},
yticklabels from table={\datatable}{Criterion},
xtick pos=bottom,
% y=0.1pt,
%
% ybar=0pt,
/pgf/bar shift=0pt,scale only axis,
width=\textwidth/3,
% yticklabel style={text width=0.035\textwidth, align=right, inner xsep=0pt, xshift=-0.005\textwidth},
% ylabel=kWh, ylabel style={text height=0.02\textwidth,inner ysep=0pt},
% enlarge x limits=0.15,
% ymin=0,
% xtick=\empty,
% tickpos=left,
% scaled y ticks=base 10:-3,
cycle list name=colorbrewer-RYB,
legend columns=-1,
legend style={draw=none, /tikz/every even column/.append style={column sep=5pt}},
legend image code/.code={%
\draw[#1] (0cm,-0.1cm) rectangle (0.3cm,0.1cm);
}
]
\nextgroupplot[xlabel=Rapperswil, legend to name=grouplegend,]
\pgfplotsinvokeforeach {0,...,\rows}{
\addplot table [ y expr=\coordindex, select row=#1, x=Rapperswil] {\datatable};
\addlegendentry {\pgfplotstablegetelem{#1}{Criterion}\of\datatable \pgfplotsretval}
}
\nextgroupplot[xlabel=Palermo]
\pgfplotsinvokeforeach {0,...,\rows}{
\addplot table [x expr=\coordindex, select row=#1, y=Palermo] {\datatable};
}
\nextgroupplot[xlabel=Jeddah]
\pgfplotsinvokeforeach {0,...,\rows}{
\addplot table [x expr=\coordindex, select row=#1, y=Jeddah] {\datatable};
}
\end{groupplot}
\end{tikzpicture}
\end{figure}
\end{document}[/code]
Vielen Dank schonmal! :)