我想改变图表以显示 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}