这是我的 MWE Latex 代码:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.11, width=10cm, height=7cm,
/pgfplots/ybar legend/.style={
/pgfplots/legend image code/.code={%
\draw [#1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);},
},
}
\begin{document}
\pgfplotstableread[col sep=comma]{
workload, EMRSAY, L-BOUND, L-MSPAN
{128M,64R}, 15409, 14105, 22906
{128M,128R}, 17501, 15079, 26405
{256M,64R}, 20312, 18509, 29619
{256M,128R}, 24590, 22123, 36960
{256M,256R}, 35152, 32519, 56176
{512M,128R}, 47490, 43012, 64597
{512M,256R}, 62789, 60002, 78179
{512M,512R}, 76596, 66159, 98357
}\PageRanka
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=.70,xscale=.70]
\begin{axis}[ybar,ymode=log,log origin=infty,log ticks with fixed point,
cycle list={{fill=white, postaction={pattern=crosshatch}}, {fill=gray, postaction={pattern=north east lines}}, {fill=white, postaction={pattern=crosshatch dots}}},
ymin=10000, ymax=100000,
ytick={10000,20000, 30000,40000,50000,60000,70000,80000,90000,100000},
bar width=0.15cm, %width=1\textwidth,
enlarge x limits=0.15,
enlarge y limits={.45, upper},
legend style={at={(1,1)}, anchor=north east, legend columns=-1},
xlabel={Wokload},
ylabel={Total energy consumption (J)},
xticklabels from table={\PageRanka}{workload},
xtick=data,
x tick label style={rotate=45,anchor=east},
]
\pgfplotsinvokeforeach {1,...,3}{
\addplot table [x expr=\coordindex, y index=#1] {\PageRanka};
}
\legend{EMRSAY,L-BOUND,L-MSPAN}
\end{axis}
\end{tikzpicture}
\end{document}
可以看出,yticks 分布不均匀。该怎么做?另外,我不希望镜像 xticks 和 yticks 分别位于相反的轴上。
答案1
这是一个对数图,因为ymode=log
。要获得或多或少等距的刻度,您需要确保两个后续刻度具有相同的比率。您可以使用xtick pos=left
和ytick pos=lower
删除不需要的刻度。(如果我是你,我会用 替换compat=1.11
。compat=1.16
)
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.11, width=10cm, height=7cm,
/pgfplots/ybar legend/.style={
/pgfplots/legend image code/.code={%
\draw [#1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);},
},
}
\begin{document}
\pgfplotstableread[col sep=comma]{
workload, EMRSAY, L-BOUND, L-MSPAN
{128M,64R}, 15409, 14105, 22906
{128M,128R}, 17501, 15079, 26405
{256M,64R}, 20312, 18509, 29619
{256M,128R}, 24590, 22123, 36960
{256M,256R}, 35152, 32519, 56176
{512M,128R}, 47490, 43012, 64597
{512M,256R}, 62789, 60002, 78179
{512M,512R}, 76596, 66159, 98357
}\PageRanka
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=.70,xscale=.70]
\begin{axis}[ybar,ymode=log,log origin=infty,log ticks with fixed point,
cycle list={{fill=white, postaction={pattern=crosshatch}}, {fill=gray, postaction={pattern=north east lines}}, {fill=white, postaction={pattern=crosshatch dots}}},
ymin=10000, ymax=100000,
%ytick={10000,20000, 30000,40000,50000,60000,70000,80000,90000,100000},
ytick={10000,30000,100000},xtick pos=left,ytick pos=lower,
bar width=0.15cm, %width=1\textwidth,
enlarge x limits=0.15,
enlarge y limits={.45, upper},
legend style={at={(1,1)}, anchor=north east, legend columns=-1},
xlabel={Workload},
ylabel={Total energy consumption (J)},
xticklabels from table={\PageRanka}{workload},
xtick=data,
x tick label style={rotate=45,anchor=east},
]
\pgfplotsinvokeforeach {1,...,3}{
\addplot table [x expr=\coordindex, y index=#1] {\PageRanka};
}
\legend{EMRSAY,L-BOUND,L-MSPAN}
\end{axis}
\end{tikzpicture}
\end{document}
或者用ytick={10000,20000,40000,80000}
。