長條圖 pgfplots 更精確

長條圖 pgfplots 更精確

我想更改圖表以顯示 14.047 小於 15,更小數精度

\documentclass[12pt,a4paper,onecolumn, openright]{report}
\usepackage{xcolor}
\usepackage{pgfplots}
\usepackage{tikz}


% Define bar chart colors
%
\definecolor{bblue}{HTML}{4F81BD}
\definecolor{rred}{HTML}{C0504D}
\definecolor{ggreen}{HTML}{9BBB59}
\definecolor{ppurple}{HTML}{9F4C7C}


\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        width  = 0.85*\textwidth,
        height = 8cm,
        major x tick style = transparent,
        y tick label style={
                /pgf/number format/fixed
                },
        ybar=2*\pgflinewidth,
        bar width=12pt,
        ymajorgrids = true,
        ylabel = {\#iterations},
        symbolic x coords={topology1,topology2,topology3,topology4,topology5},
        xtick = data,
        scaled y ticks = false,
        enlarge x limits=0.12,
        ymin=0,
        ymax=20,
        legend style={at={(0.5,-0.15)}, anchor=north,legend columns=-1},
 ]
        \addplot[style={bblue,fill=bblue,mark=none}]
            coordinates {(topology1, 15) (topology2,12) (topology3,11)(topology4, 9) (topology5,9) };
        \addplot[style={ppurple,fill=ppurple,mark=none}]
             coordinates {(topology1,18.047) (topology2,15.047) (topology3,14.047)(topology4, 12.047) (topology5,12.047)};

        \addplot[style={ggreen,fill=ggreen,mark=none}]
             coordinates {(topology1,18.047) (topology2,15.047) (topology3,14.047)(topology4, 12.047) (topology5,12.047)};


        \legend{MARA-MC,MARA-MMMF,MARA-SPE}
    \end{axis}
\end{tikzpicture}
\end{document}

答案1

您可以變更圖形高度和 y 軸範圍以「放大」資料。我將圖表設定為 18 公分高,ymin=8.5,ymax=19。這顯示了你的與眾不同。

然而,這可能不是最好的解決方案。鑑於差異很小,您可能想要考慮解釋文字中的數據,或以不同的方式表示它,也許使用繪圖上的值。

\documentclass[12pt,a4paper,onecolumn, openright]{report}
\usepackage{xcolor}
\usepackage{pgfplots}
\usepackage{tikz}


% Define bar chart colors
%
\definecolor{bblue}{HTML}{4F81BD}
\definecolor{rred}{HTML}{C0504D}
\definecolor{ggreen}{HTML}{9BBB59}
\definecolor{ppurple}{HTML}{9F4C7C}


\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        width  = 0.85*\textwidth,
        height = 18cm,
        major x tick style = transparent,
        y tick label style={
                /pgf/number format/fixed
                },
        ybar=2*\pgflinewidth,
        bar width=12pt,
        ymajorgrids = true,
        ylabel = {\#iterations},
        symbolic x coords={topology1,topology2,topology3,topology4,topology5},
        xtick = data,
        scaled y ticks = false,
        enlarge x limits=0.12,
        ymin=8.5,
        ymax=19,
        legend style={at={(0.5,-0.15)}, anchor=north,legend columns=-1},
 ]
        \addplot[style={bblue,fill=bblue,mark=none}]
            coordinates {(topology1, 15) (topology2,12) (topology3,11)(topology4, 9) (topology5,9) };
        \addplot[style={ppurple,fill=ppurple,mark=none}]
             coordinates {(topology1,18.047) (topology2,15.047) (topology3,14.047)(topology4, 12.047) (topology5,12.047)};

        \addplot[style={ggreen,fill=ggreen,mark=none}]
             coordinates {(topology1,18.047) (topology2,15.047) (topology3,14.047)(topology4, 12.047) (topology5,12.047)};


        \legend{MARA-MC,MARA-MMMF,MARA-SPE}
    \end{axis}
\end{tikzpicture}
\end{document}

相關內容