TransWikia.com

Creating a stacked bargraph with tikz, without values changing

TeX - LaTeX Asked by user214704 on May 8, 2021

i would like to add another bar within each bar to represent the constant time. Like shown in the image below (GREEN colour). Its kind of like a stacked bar graph but i just want to show that there a constant time there to read in a image.

begin{figure}[!h]
centering
begin{tikzpicture}
begin{axis}[
    ybar,
    ymin=0,
    %enlargelimits=0.15,
                legend image code/.code={%
                    draw[#1, draw=none] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
                },  
    legend style={at={(0.5,-0.10)},
      anchor=north,legend columns=-1},
    ylabel={Execution Time (ms)},
    symbolic x coords={RGB2GRAY,Gaussian,Box, Sobel},
    xtick=data,
    nodes near coords,
    nodes near coords align={vertical},
    ]
addplot coordinates {(RGB2GRAY,54) (Gaussian,86)  (Box,154) (Sobel,268)  };%CPU
addplot coordinates {(RGB2GRAY,170.71) (Gaussian, 172.065)  (Box,193.72) (Sobel,215.38)  };%GPU
addplot coordinates {(RGB2GRAY,20.234959834) (Gaussian,26.492609995)  (Box,27.353843832) (Sobel,45.59262995) };%FPGA
legend{CPU,GPU,FPGA}
end{axis}
end{tikzpicture}
caption{Algorithms Including Image Read/Write }
end{figure}

enter image description here

One Answer

Welcome! A rather blunt way is to superimpose a second, "hidden" (hide axis) axis. To "synchronize the axes, you may want to use ymin=0,ymax=300, for both.

documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=1.17}
begin{document}
begin{figure}[!h]
centering
begin{tikzpicture}
begin{axis}[
    ybar,
    ymin=0,ymax=300,%<- added ymax
    %enlargelimits=0.15,
                legend image code/.code={%
                    draw[#1, draw=none] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
                },  
    legend style={at={(0.5,-0.10)},
      anchor=north,legend columns=-1},
    ylabel={Execution Time (ms)},
    symbolic x coords={RGB2GRAY,Gaussian,Box, Sobel},
    xtick=data,
    nodes near coords,
    nodes near coords align={vertical},
    ]
addplot coordinates {(RGB2GRAY,54) (Gaussian,86)  (Box,154) (Sobel,268)  };%CPU
addplot coordinates {(RGB2GRAY,170.71) (Gaussian, 172.065)  (Box,193.72) (Sobel,215.38)  };%GPU
addplot coordinates {(RGB2GRAY,20.234959834) (Gaussian,26.492609995)  (Box,27.353843832) (Sobel,45.59262995) };%FPGA
legend{CPU,GPU,FPGA}
end{axis}
begin{axis}[ybar,ymin=0,ymax=300,hide axis,
    symbolic x coords={RGB2GRAY,Gaussian,Box, Sobel}
    ]
addplot[fill=green] coordinates {(RGB2GRAY,100) (Gaussian,100)  (Box,100) (Sobel,100)  };
end{axis}
end{tikzpicture}
caption{Algorithms Including Image Read/Write }
end{figure}
end{document}

enter image description here

Answered by user194703 on May 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP