我有以下代码:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=12cm,compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={Testbench: Bitzähler (Speicher)},
xlabel={Reduktionsarten},
ylabel={Fehlerstellen},
major x tick style=transparent,
ybar=2*\pgflinewidth,
bar width=25pt,
x tick label style={rotate=0, anchor=center},
symbolic x coords={ALL, WRITE, READ},
ymax=2500,
xtick=data,
ytick={1,10,100,1000,10000},
legend pos= outer north east,
ymajorgrids=true,
grid style=dashed,
ymode=log,
log basis y={10},
enlarge x limits=0.25,
nodes near coords,
point meta=explicit symbolic
]
%NONE
\addplot[fill=red!60] coordinates {
(ALL,1408)[\textcolor{red!60}{1408}]
(WRITE,352)[\textcolor{red!60}{352}]
(READ,1056)[\textcolor{red!60}{1056}]
};
%MODIFIER
\addplot[fill=blue!60] coordinates {
(ALL,1408)[\textcolor{blue!60}{1408}]
(WRITE,352)[\textcolor{blue!60}{352}]
(READ,1056)[\textcolor{blue!60}{1056}]
};
\addplot[fill=yellow!60] coordinates {
(READ,1056)[\textcolor{yellow!60}{1056}]};
\addplot[fill=green!60] coordinates {
(READ,1056)[\textcolor{green!60}{1056}]};
\legend{NONE, MODIFIKATOR, ÄQUIVALENZKLASSE, ÄQUI + MODI}
\end{axis}
\end{tikzpicture}
\end{document}
它看起来像这样:
我怎样才能将ALL
和WRITE
条形图对齐到中间?我相信它已经对齐了,但其他 2 条形图在这里为 0。但它们需要位于WRITE
和ALL
点上方。我怎样才能在ALL
、WRITE
和READ
文本与 x 轴之间留出更多空间?颜色也很难看。:( 像下图这样的东西更漂亮。
我该怎么做?我怎样才能让我的图表更漂亮呢?
抱歉问了这么多问题。我有点着急,因为明天我要交论文。希望你们理解!提前谢谢大家!!
答案1
我不知道该如何回应“颜色太丑了”,毕竟这些颜色是你选的。不过,改变一下很容易xtick labels
。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=12cm,compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={Testbench: Bitzähler (Speicher)},
xlabel={Reduktionsarten},
ylabel={Fehlerstellen},
major x tick style=transparent,
ybar=2*\pgflinewidth,
bar width=25pt,
x tick label style={rotate=0, anchor=center},
symbolic x coords={ALL, WRITE, READ},
xticklabel style={yshift=-2mm,xshift={ifthenelse(\ticknum==2,0,-26)}},
ymax=2500,
xtick=data,
ytick={1,10,100,1000,10000},
legend pos= outer north east,
ymajorgrids=true,
grid style=dashed,
ymode=log,
log basis y={10},
enlarge x limits=0.25,
nodes near coords,
point meta=explicit symbolic
]
%NONE
\addplot[fill=red!60] coordinates {
(ALL,1408)[\textcolor{red!60}{1408}]
(WRITE,352)[\textcolor{red!60}{352}]
(READ,1056)[\textcolor{red!60}{1056}]
};
%MODIFIER
\addplot[fill=blue!60] coordinates {
(ALL,1408)[\textcolor{blue!60}{1408}]
(WRITE,352)[\textcolor{blue!60}{352}]
(READ,1056)[\textcolor{blue!60}{1056}]
};
\addplot[fill=yellow!60] coordinates {
(READ,1056)[\textcolor{yellow!60}{1056}]};
\addplot[fill=green!60] coordinates {
(READ,1056)[\textcolor{green!60}{1056}]};
\legend{NONE, MODIFIKATOR, ÄQUIVALENZKLASSE, ÄQUI + MODI}
\end{axis}
\end{tikzpicture}
\end{document}
在澄清你关于颜色的陈述的含义后,我建议
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=12cm,compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={Testbench: Bitzähler (Speicher)},
xlabel={Reduktionsarten},
ylabel={Fehlerstellen},
major x tick style=transparent,
ybar=2*\pgflinewidth,
bar width=25pt,
x tick label style={rotate=0, anchor=center},
symbolic x coords={ALL, WRITE, READ},
xticklabel style={yshift=-2mm,xshift={ifthenelse(\ticknum==2,0,-26)}},
ymax=2500,
xtick=data,
ytick={1,10,100,1000,10000},
legend pos= outer north east,
ymajorgrids=true,
grid style=dashed,
ymode=log,
log basis y={10},
enlarge x limits=0.25,
nodes near coords,
point meta=explicit symbolic
]
%NONE
\addplot[draw=red,thick,fill=red,fill opacity=0.6] coordinates {
(ALL,1408)[\textcolor{red!60}{1408}]
(WRITE,352)[\textcolor{red!60}{352}]
(READ,1056)[\textcolor{red!60}{1056}]
};
%MODIFIER
\addplot[draw=blue,thick,fill=blue,fill opacity=0.6] coordinates {
(ALL,1408)[\textcolor{blue!60}{1408}]
(WRITE,352)[\textcolor{blue!60}{352}]
(READ,1056)[\textcolor{blue!60}{1056}]
};
\addplot[draw=orange,thick,fill=orange,fill opacity=0.6] coordinates {
(READ,1056)[\textcolor{yellow!60}{1056}]};
\addplot[draw=green!60!black,thick,fill=green!60!black,fill opacity=0.6] coordinates {
(READ,1056)[\textcolor{green!60}{1056}]};
\legend{NONE, MODIFIKATOR, ÄQUIVALENZKLASSE, ÄQUI + MODI}
\end{axis}
\end{tikzpicture}
\end{document}
(请注意,由于某种原因,我的编译器抑制了变音符号。我相信您不会遇到这个问题。但是,我不知道如何使变音符号出现。我只是用 进行编译xelatex
。)