TransWikia.com

Graph to show the differences - Increase or decrease

TeX - LaTeX Asked by John Marshall on April 27, 2021

Hope you can help me with this question and I apologize if it contains several questions at once. I am stuck with how I can show a comparison of several experiments in the way I need them.

I am doing this for several experiments. I changed the values of ymin and ymax as the (maximum) one was not appearing or the others overlapping.

In some experiments the values I will be comparing will sometimes be too large. Below is one of them where I am getting an error Dimension too large. So I wanted to know whether the ymin and ymax can be changed dynamically as I have 18 parameters I will be comparing like this Thanks again

Thanks to the help of Excelsior I have done so far some of the experiments, however other experiments that have large values becomes too crowded or overlap.

enter image description here

The first one is okay as the values are small (x axis values needs spacing)
the second one is not working as you can see.
Any help will be appreciated.

MWE

  documentclass[border=5pt]{standalone}
  usepackage{tikz}

  pgfplotsset{ 
    compat=newest,  
    mystyle/.style={    
        ybar,   
        xtick={1,2,3,4,5,6},    
        xticklabels={short[ref{Ch4}], short[ref{Ch4}], short[ref{Ch5}], short[ref{Ch5}], longggggg[ref{Ch4}], longggggg[ref{Ch5}]},   
        xtick pos=left, % x ticks only at the bottom of the plot    
        xtick align=inside, % x ticks inside the plot   
        ytick pos=left, % y ticks only at the left side 
        nodes near coords,  
        nodes near coords style={font=tiny, fill=white, inner sep=2pt}, % sets style for the labels above the bars 
        every tick label/.append style={font=small}, % change font of tick labels  
        xmin=0.75,  
        xmax=6.25,  
        bar width=9pt,  
        line width=0.1pt,   
    }   
}   

begin{tikzpicture} 
    begin{axis}[   
        mystyle,    
        ymin=-5,    
        ymax=80000, 
        ytick={5}, % added the y label  
        yticklabels={Average},  
        xmajorgrids=true % show only grid of x values   
        ]   
        addplot [  
        draw=black, 
        fill=green  
        ] coordinates   
        {(1,51265.35) (2,41693.34 ) (3,54873.07) (4,46233.52) (5,66678.20) (6,71367.09)};   
        
        draw[-stealth, thick, red] (1.25,51265.35) -- (1.75,41693.34); 
        draw[-stealth, thick, red] (2.25,41693.34) -- (2.75,54873.07); 
        draw[-stealth, thick, red] (3.25,54873.07) -- (3.75,46233.52); 
        draw[-stealth, thick, red] (4.25,46233.52) -- (4.75,66678.20); 
        draw[-stealth, thick, red] (5.25,66678.20) -- (5.75,71367.09); 
        
    end{axis}  
    
    begin{axis}[   
        mystyle,    
        ymin=-35,   
        ymax=65,    
        ytick={5}, % added the y label  
        yticklabels={Minmum},   
        ]   
        addplot [  
        draw=black,     
        fill=blue   
        ] coordinates   
        {(1,3.52) (2,3.16 ) (3,7.41) (4,7.10) (5,15.92) (6,12.98)}; 
        
        draw[-stealth, thick, red] (1.25,3.52) -- (1.75,3.16); 
        draw[-stealth, thick, red] (2.25,3.16) -- (2.75,7.41); 
        draw[-stealth, thick, red] (3.25,7.41) -- (3.75,7.10); 
        draw[-stealth, thick, red] (4.25,7.10) -- (4.75,15.92);    
        draw[-stealth, thick, red] (5.25,15.92) -- (5.75,12.98);   
    end{axis}  
    
    begin{axis}[   
        mystyle,    
        ymin=-80,   
        ymax=35000, 
        ytick={5}, % added the y label  
        yticklabels={Maximum},  
        ]   
        addplot [  
        draw=black,     
        fill=yellow 
        ] coordinates   
        {(1,250495.61) (2,200165.27 ) (3,255111.54) (4,230207.42) (5,325664.59) (6,331691.12)}; 
        
        draw[-stealth, thick, red] (1.25,250495.61) -- (1.75,200165.27);   
        draw[-stealth, thick, red] (2.25,200165.27) -- (2.75,255111.54);   
        draw[-stealth, thick, red] (3.25,200165.27) -- (3.75,230207.42);   
        draw[-stealth, thick, red] (4.25,230207.42) -- (4.75,325664.59);   
        draw[-stealth, thick, red] (5.25,325664.59) -- (5.75,331691.12);   
    end{axis}  
 end{tikzpicture}
end{document}

One Answer

I fixed some parts of your code (put some comments in the MWE) and plotted the arrows using the coordinated as starting and end point. The result looks like this:

enter image description here

documentclass[border=5pt]{standalone}

usepackage{pgfplots}

begin{document}
    
    pgfplotsset{
        compat=newest,
        mystyle/.style={
            ybar,
            xtick={1,2,3,4,5,6},
            xticklabels={1[ref{Ch4}], 2[ref{Ch4}], 3[ref{Ch5}], 4[ref{Ch5}], 5[ref{Ch4}], 6[ref{Ch5}]},
            tick align=inside, % all ticks inside (for equal distance of x and y labels)
            tick style={draw=none}, % you don't need to show the ticks
            nodes near coords,
            nodes near coords style={font=tiny, fill=white, inner sep=2pt}, % change style of the numbers above the bars
            every tick label/.append style={font=small}, % change font of tick labels
            xmin=0.75,
            xmax=6.25, 
            bar width=9pt, 
            line width=0.1pt,
        }
    }
    
    begin{tikzpicture}
        begin{axis}[
            mystyle,
            ymin=-5,
            ymax=95,
            ytick={8.5}, % position y label at the middle of the plot
            yticklabels={exp1},
            xmajorgrids=true % show only grid for x values
            ]
            addplot [
            draw=black,
            fill=green
            ] coordinates
            {(1,1) (2,2) (3,3) (4,7) (5,10) (6,17)};
            
            draw[-stealth, thick, red] (axis cs:1.25,1) -- (axis cs:1.75,2);
            draw[-stealth, thick, red] (axis cs:2.25,2) -- (axis cs:2.75,3);
            draw[-stealth, thick, red] (axis cs:3.25,3) -- (axis cs:3.75,7);
            draw[-stealth, thick, red] (axis cs:4.25,7) -- (axis cs:4.75,10);
            draw[-stealth, thick, red] (axis cs:5.25,10) -- (axis cs:5.75,17);
            
        end{axis}
                
        begin{axis}[
            mystyle,
            ymin=-35,
            ymax=65,
            ytick={17.5}, % position y label at the middle of the plot
            yticklabels={exp2},
            ]
            addplot [
            draw=black, 
            fill=blue
            ] coordinates
            {(1,32) (2,35) (3,13) (4,4) (5,1) (6,4)};
            
            draw[-stealth, thick, red] (axis cs:1.25,32) -- (axis cs:1.75,35);
            draw[-stealth, thick, red] (axis cs:2.25,35) -- (axis cs:2.75,13);
            draw[-stealth, thick, red] (axis cs:3.25,13) -- (axis cs:3.75,4);
            draw[-stealth, thick, red] (axis cs:4.25,4) -- (axis cs:4.75,1);
            draw[-stealth, thick, red] (axis cs:5.25,1) -- (axis cs:5.75,4);
        end{axis}
        
        begin{axis}[
            mystyle,
            ymin=-80,
            ymax=20,
            ytick={7}, % position y label at the middle of the plot
            yticklabels={exp3},
            ]
            addplot [
            draw=black, 
            fill=yellow
            ] coordinates
            {(1,5) (2,9) (3,13) (4,14) (5,7) (6,6)};
            
            draw[-stealth, thick, red] (axis cs:1.25,5) -- (axis cs:1.75,9);
            draw[-stealth, thick, red] (axis cs:2.25,9) -- (axis cs:2.75,13);
            draw[-stealth, thick, red] (axis cs:3.25,13) -- (axis cs:3.75,14);
            draw[-stealth, thick, red] (axis cs:4.25,14) -- (axis cs:4.75,7);
            draw[-stealth, thick, red] (axis cs:5.25,7) -- (axis cs:5.75,6);
        end{axis}
    end{tikzpicture}
end{document}

EDIT

Regarding the questions asked in the comments:

Q1 How do you focus this based on the values, so for example I have another parameter I want to compare and the values are a lot larger (I am assuming it is the ymin and ymin) Is there anyway we can change this dynamically?

In case you mean the arrows: The command draw[-stealth, thick, red] (axis cs:1st x value + 0.25, start y value) -- (axis cs:2nd x value - 0.25, end y value); can be tuned, if you change the x and y values.

Q2 How can we increase the distance between the y axis values - xlabels will need to be changed for me and they are overlapping?

In case you mean the x axis labels, you can increase the x values of your coordinates (and additionally the xmin and xmax values) for higher horizontal shift.

Otherwise, see comment ...

EDIT 2

Now regarding your problems, I did some changed to the code. The result looks like this:

enter image description here

documentclass[border=5pt]{standalone}

usepackage{pgfplots}
usetikzlibrary{calc}

begin{document}

pgfplotsset{ 
    compat=newest,  
    mystyle/.style={    
        ybar,   
        xtick={2,4,6,8,10,12},    
        xticklabels={OF0 [ref{Ch4}], ETX  [ref{Ch4}], OF0 [ref{Ch5}], ETX [ref{Ch5}], SISLOF  [ref{Ch4}], SISLOF [ref{Ch5}]}, 
        tick align=inside, % ticks inside plot (only nessesary for equal alignment of the labels)
        tick style={draw=none}, % remove the ticks, since you don't need them
        nodes near coords,  
        nodes near coords style={font=tiny, fill=white, inner sep=2pt, rotate=90, right}, % sets style for the labels above the bars 
        every x tick label/.append style={font=small, rotate=90}, % change font of tick labels 
        xmajorgrids=true, % show only grid of x values
        xmin=0.5, % change min and max value for better horizontal spacing 
        xmax=13.5,
        enlarge y limits={value=0.35,upper}, % some y offset for the text
        scaled y ticks=false, % no scaling factors for y labels
        bar width=9pt,  
        line width=0.1pt,   
    }   
}   

    begin{tikzpicture} 
        begin{axis}[
            name=average,  
            mystyle,
            ymin=0,
            ymax=72000, 
            ytick={36000}, % added the y label  
            yticklabels={Average},   
            ]   
            addplot [  
            draw=black, 
            fill=green  
            ] coordinates   
            {(2,51265.35) (4,41693.34 ) (6,54873.07) (8,46233.52) (10,66678.20) (12,71367.09)};   
            
            draw[-stealth, thick, red] (2.5,51265.35) -- (3.5,41693.34); 
            draw[-stealth, thick, red] (4.5,41693.34) -- (5.5,54873.07); 
            draw[-stealth, thick, red] (6.5,54873.07) -- (7.5,46233.52); 
            draw[-stealth, thick, red] (8.5,46233.52) -- (9.5,66678.20); 
            draw[-stealth, thick, red] (10.5,66678.20) -- (11.5,71367.09); 
            
        end{axis}  
        
        begin{axis}[
            name=minimum,
            at={($(average.north)$)}, 
            anchor=south,  
            mystyle, 
            xticklabels={,,}, % no x labels
            ymin=0,
            ymax=16,
            ytick={8}, % added the y label  
            yticklabels={Minmum},   
            ]   
            addplot [  
            draw=black,     
            fill=blue   
            ] coordinates   
            {(2,3.52) (4,3.16 ) (6,7.41) (8,7.10) (10,15.92) (12,12.98)}; 
            
            draw[-stealth, thick, red] (2.5,3.52) -- (3.5,3.16); 
            draw[-stealth, thick, red] (4.5,3.16) -- (5.5,7.41); 
            draw[-stealth, thick, red] (6.5,7.41) -- (7.5,7.10); 
            draw[-stealth, thick, red] (8.5,7.10) -- (9.5,15.92);    
            draw[-stealth, thick, red] (10.5,15.92) -- (11.5,12.98);   
        end{axis}  
        
        begin{axis}[
            name=minimum,
            at={($(minimum.north)$)}, 
            anchor=south,  
            mystyle,
            xticklabels={,,}, % no x labels
            ymin=0,
            ymax=332000,
            ytick={166000}, % added the y label  
            yticklabels={Maximum},  
            ]   
            addplot [  
            draw=black,     
            fill=yellow 
            ] coordinates   
            {(2,250495.61) (4,200165.27 ) (6,255111.54) (8,230207.42) (10,325664.59) (12,331691.12)};   
            
            draw[-stealth, thick, red] (2.5,250495.61) -- (3.5,200165.27);   
            draw[-stealth, thick, red] (4.5,200165.27) -- (5.5,255111.54);   
            draw[-stealth, thick, red] (6.5,255111.54) -- (7.5,230207.42);   
            draw[-stealth, thick, red] (8.5,230207.42) -- (9.5,325664.59);   
            draw[-stealth, thick, red] (10.5,325664.59) -- (11.5,331691.12);   
        end{axis}  
    end{tikzpicture}
end{document}

So my new attempt is to plot each of the three plots individually and stick them on top of each other using calc library. In case it is vertically to high, you can tune it defining some heigth and width in each axis environment.

EDIT 3

I think this look good now:

enter image description here

documentclass[border=5pt]{standalone}

usepackage{pgfplots}
usetikzlibrary{calc}

begin{document}

pgfplotsset{ 
    compat=newest,  
    mystyle/.style={    
        ybar,   
        xtick={2,4,6,8,10,12},    
        xticklabels={OF0 [ref{Ch4}], ETX  [ref{Ch4}], OF0 [ref{Ch5}], ETX [ref{Ch5}], SISLOF  [ref{Ch4}], SISLOF [ref{Ch5}]}, 
        tick align=inside,
        tick style={draw=none},
        nodes near coords,  
        nodes near coords style={font=tiny, fill=white, inner sep=2pt, above=5pt}, % sets style for the labels above the bars 
        every x tick label/.append style={font=small, rotate=45}, % change font of tick labels 
        xmajorgrids=true, % show only grid of x values
        xmin=0.5,  
        xmax=13.5,
        enlarge y limits={value=0.15,upper},
        scaled y ticks=false,
        bar width=9pt,  
        line width=0.1pt,
        scale only axis=true,
        height=4cm,
        width=12cm,
    }   
}   

    begin{tikzpicture} 
        begin{axis}[
            name=average,
            mystyle,
            ymin=0,
            ymax=72000, 
            ytick={36000}, % added the y label  
            yticklabels={Average},   
            ]   
            addplot [  
            draw=black, 
            fill=green  
            ] coordinates   
            {(2,51265.35) (4,41693.34 ) (6,54873.07) (8,46233.52) (10,66678.20) (12,71367.09)};   
            
            draw[-stealth, thick, red] (2.5,51265.35) -- (3.5,41693.34); 
            draw[-stealth, thick, red] (4.5,41693.34) -- (5.5,54873.07); 
            draw[-stealth, thick, red] (6.5,54873.07) -- (7.5,46233.52); 
            draw[-stealth, thick, red] (8.5,46233.52) -- (9.5,66678.20); 
            draw[-stealth, thick, red] (10.5,66678.20) -- (11.5,71367.09); 
            
        end{axis}  
        
        begin{axis}[
            name=minimum,
            at={($(average.north)$)}, 
            anchor=south,  
            mystyle, 
            xticklabels={,,},
            ymin=0,
            ymax=16,
            ytick={8}, % added the y label  
            yticklabels={Minmum},   
            ]   
            addplot [  
            draw=black,     
            fill=blue   
            ] coordinates   
            {(2,3.52) (4,3.16 ) (6,7.41) (8,7.10) (10,15.92) (12,12.98)}; 
            
            draw[-stealth, thick, red] (2.5,3.52) -- (3.5,3.16); 
            draw[-stealth, thick, red] (4.5,3.16) -- (5.5,7.41); 
            draw[-stealth, thick, red] (6.5,7.41) -- (7.5,7.10); 
            draw[-stealth, thick, red] (8.5,7.10) -- (9.5,15.92);    
            draw[-stealth, thick, red] (10.5,15.92) -- (11.5,12.98);   
        end{axis}  
        
        begin{axis}[
            name=minimum,
            at={($(minimum.north)$)}, 
            anchor=south,  
            mystyle,
            xticklabels={,,},
            ymin=0,
            ymax=332000,
            ytick={166000}, % added the y label  
            yticklabels={Maximum},  
            ]   
            addplot [  
            draw=black,     
            fill=yellow 
            ] coordinates   
            {(2,250495.61) (4,200165.27 ) (6,255111.54) (8,230207.42) (10,325664.59) (12,331691.12)};   
            
            draw[-stealth, thick, red] (2.5,250495.61) -- (3.5,200165.27);   
            draw[-stealth, thick, red] (4.5,200165.27) -- (5.5,255111.54);   
            draw[-stealth, thick, red] (6.5,255111.54) -- (7.5,230207.42);   
            draw[-stealth, thick, red] (8.5,230207.42) -- (9.5,325664.59);   
            draw[-stealth, thick, red] (10.5,325664.59) -- (11.5,331691.12);   
        end{axis}  
    end{tikzpicture}
end{document}

Answered by Excelsior on April 27, 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