如何绘制小条与长条的组合?

如何绘制小条与长条的组合?

所有组中的第一个条形不可见。如何使其可见?

这是不起作用的 MWE。

\documentclass{article}
\usepackage[a4paper, left=1in, right=1in, top=1.5in, bottom=1.5in]{geometry}
\usepackage{pgfplots}\usepackage{graphicx}
\usepackage{pgfplotstable}\usepackage{caption} 
\usepackage{subcaption}

\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},     0.004,      0.4,        0.4
    {128M,128R},    0.005,      0.6,        0.6
    {256M,64R},     0.006,      0.8,        0.8
    {256M,128R},    0.007,      0.8,        0.8
    {256M,256R},    0.007,      1.0,        1.0
    {512M,128R},    0.008,      1.0,        1.0
    {512M,256R},    0.008,      1.1,        1.1
    {512M,512R},    0.009,      1.4,        1.4

}\PageRankb

\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=.80,xscale=.80]

\begin{axis}[
%x tick label style={/pgf/number format/1000 sep=},
ybar,
cycle list={{fill=white, postaction={pattern=crosshatch}}, {fill=gray, postaction={pattern=north east lines}}, {fill=white, postaction={pattern=crosshatch dots}}},
ymin=0.001, ymax=2,
ytick={0.001,0.01,0.1,1},
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={Execution time (s)},
xticklabels from table={\PageRankb}{workload},
xtick=data,
x tick label style={rotate=45,anchor=east},
%nodes near coords,%vaule of data over the bar
%nodes near coords align={vertical}
]

\pgfplotsinvokeforeach {1,...,3}{
    \addplot table [x expr=\coordindex, y index=#1] {\PageRankb};
}
\legend{1st, 2nd, 3rd}
\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

我想要一个与以下类似且具有相同 yticks 的条形图:

在此处输入图片描述

答案1

由于条形图的高度层次较大,因此您可能需要使用对数图。可以通过调整按键来控制刻度标签和刻度。

\documentclass{article}
\usepackage[a4paper, left=1in, right=1in, top=1.5in, bottom=1.5in]{geometry}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{subcaption}

\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},     0.004,      0.4,        0.4
    {128M,128R},    0.005,      0.6,        0.6
    {256M,64R},     0.006,      0.8,        0.8
    {256M,128R},    0.007,      0.8,        0.8
    {256M,256R},    0.007,      1.0,        1.0
    {512M,128R},    0.008,      1.0,        1.0
    {512M,256R},    0.008,      1.1,        1.1
    {512M,512R},    0.009,      1.4,        1.4

}\PageRankb

\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=.80,xscale=.80]

\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=0.001, ymax=2,
ytick={0.001,0.01,0.1,1},
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={Execution time (s)},
xticklabels from table={\PageRankb}{workload},
xtick=data,
x tick label style={rotate=45,anchor=east}]

\pgfplotsinvokeforeach {1,...,3}{
    \addplot table [x expr=\coordindex, y index=#1] {\PageRankb};
}
\legend{1st, 2nd, 3rd}
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

不绘制 y 轴刻度:

\documentclass{article}
\usepackage[a4paper, left=1in, right=1in, top=1.5in, bottom=1.5in]{geometry}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{subcaption}

\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},     0.004,      0.4,        0.4
    {128M,128R},    0.005,      0.6,        0.6
    {256M,64R},     0.006,      0.8,        0.8
    {256M,128R},    0.007,      0.8,        0.8
    {256M,256R},    0.007,      1.0,        1.0
    {512M,128R},    0.008,      1.0,        1.0
    {512M,256R},    0.008,      1.1,        1.1
    {512M,512R},    0.009,      1.4,        1.4

}\PageRankb

\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=.80,xscale=.80]

\begin{axis}[ybar,ymode=log,log origin=infty,log ticks with fixed point,
ytick style={draw=none},
cycle list={{fill=white, postaction={pattern=crosshatch}}, {fill=gray, postaction={pattern=north east lines}}, {fill=white, postaction={pattern=crosshatch dots}}},
ymin=0.001, ymax=2,
ytick={0.001,0.01,0.1,1},
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={Execution time (s)},
xticklabels from table={\PageRankb}{workload},
xtick=data,
x tick label style={rotate=45,anchor=east}]

\pgfplotsinvokeforeach {1,...,3}{
    \addplot table [x expr=\coordindex, y index=#1] {\PageRankb};
}
\legend{1st, 2nd, 3rd}
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容