LaTeX图表Y轴小数显示格式调整求助:需按指定数值展示
解决PGFPlots Y轴刻度格式显示问题
你设置的Y轴刻度是0.004、0.005……0.018这类三位小数,但当前代码里仅用了/pgf/number format/fixed,PGFPlots会自动省略末尾的零,导致像0.01这类刻度只显示成0.01,不符合你想要的统一三位小数格式。
只需修改yticklabel style的设置,加上强制小数位数和补零的参数即可:
yticklabel style={/pgf/number format/fixed, /pgf/number format/precision=3, /pgf/number format/fixed zerofill},
修改后的完整代码如下:
\documentclass{article} \usepackage{graphicx} % Required for inserting images \usepackage{pgfplots} \begin{document} \begin{figure} \centering \begin{tikzpicture} [style={outer sep=5}] \begin{axis}[ymin=0.004,ymax=0.018, xmin=15, xmax=50, xlabel= $Number of Nodes$, ylabel = $end-to-end (sec)$, xtick={15,20,...,50}, ytick={0.004,0.005,...,0.018}, yticklabel style={/pgf/number format/fixed, /pgf/number format/precision=3, /pgf/number format/fixed zerofill}, grid={major},clip=false,grid style={dashed}, title={}, legend style={at={(1.2 ,1)},anchor=north}, font=\footnotesize] % TAODV \addplot[color=blue, mark=*, samples=10] [error bars/.cd,y dir=both, y explicit] coordinates { (15, 0.0072) +-(0.001, -0.001) (20, 0.0079) +-(0.001, -0.001) (25, 0.0092) +-(0.001, -0.001) (30, 0.01) +-(0.001, -0.001) (35, 0.013) +-(0.0018, -0.0018) (40, 0.0137) +-(0.001, -0.001) (45, 0.015) +-(0.001, -0.001) (50, 0.0168)+-(0.001, -0.001) }; % AODV \addplot[color=red, mark=*, samples=10] [error bars/.cd,y dir=both, y explicit] coordinates { (15, 0.0052) +-(0.001, -0.001) (20, 0.0057) +-(0.001, -0.001) (25, 0.0067) +-(0.001, -0.001) (30, 0.0074) +-(0.001, -0.001) (35, 0.0082) +-(0.0018, -0.0018) (40, 0.0095) +-(0.001, -0.001) (45, 0.01) +-(0.001, -0.001) (50, 0.0109) +-(0.001, -0.001) }; \legend{ $TAODV$, $AODV$ } \end{axis} \end{tikzpicture} \caption[End-to-end delay of TAODV vs. AODV]{End-to-end delay of TAODV vs. AODV with \%95 confidence interval} \end{figure} \end{document}
其中:
/pgf/number format/precision=3:指定刻度显示3位小数/pgf/number format/fixed zerofill:自动填充末尾的零,保证所有刻度的小数位数统一
内容的提问来源于stack exchange,提问作者Ali Alzahrani
相关产品推荐
相关产品推荐

