图表显示差异 - 增加或减少

图表显示差异 - 增加或减少

希望您能帮我解答这个问题,如果这个问题同时包含多个问题,我深表歉意。我不知道如何以我需要的方式显示多个实验的比较。

我正在为几个实验做这个。我改变了 ymin 和 ymax 的值,因为(最大值)一个没有出现,或者其他值重叠。

在一些实验中,我要比较的值有时会太大。下面是我遇到错误的一个实验Dimension too large。所以我想知道 ymin 和 ymax 是否可以动态更改,因为我有 18 个参数,我将像这样进行比较,再次感谢

感谢 Excelsior 的帮助,到目前为止我已经完成了一些实验,但是其他具有较大值的实验变得过于拥挤或重叠。

在此处输入图片描述

第一个没问题,因为值很小(x 轴值需要间距),第二个不起作用,如您所见。任何帮助都将不胜感激。

平均能量损失

  \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}

答案1

我修复了代码的某些部分(在 MWE 中添加了一些注释),并使用坐标作为起点和终点绘制了箭头。结果如下所示:

在此处输入图片描述

\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}

编辑

关于评论中提出的问题:

问题 1 您如何根据值来关注这一点,例如,我有另一个想要比较的参数,并且值要大得多(我假设它是 ymin 和 ymin)我们有什么办法可以动态地改变它吗?

如果你指的是箭头:\draw[-stealth, thick, red] (axis cs:1st x value + 0.25, start y value) -- (axis cs:2nd x value - 0.25, end y value);如果你改变,命令就可以进行调整x and y values

第二季度 我们如何增加 y 轴值之间的距离 - xlabels 需要为我更改并且它们重叠?

如果您指的是 x 轴标签,您可以增加坐标的 x 值(以及 xmin 和 xmax 值)以实现更高的水平偏移。

否则,请参阅评论...

编辑2

现在关于你的问题,我对代码做了一些修改。结果如下:

在此处输入图片描述

\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}

因此,我的新尝试是分别绘制三个图,然后使用calc库将它们粘贴在一起。如果垂直方向太高,您可以在每个环境中定义一些heigth和来调整它。widthaxis

编辑3

我认为现在看起来不错:

在此处输入图片描述

\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}

相关内容