PGFPlots는 노드와 틱에 전체 십진수를 표시합니다.

PGFPlots는 노드와 틱에 전체 십진수를 표시합니다.

다음 그래프가 있습니다

여기에 이미지 설명을 입력하세요

그리고 y 눈금 축과 막대 위에 소수점 숫자를 적어야 합니다. 나는 여기에서 를 사용하라는 다른 질문을 발견했는데 y tick label style={/pgf/number format/fixed}, 그것은 나에게 전혀 도움이 되지 않았으며 scaled ticks=false, 어떤 종류는 축에 대해 작동했지만 몇 가지 이상한 일을 만들어 바에 대해서는 작동하지 않았습니다.

여기에 이미지 설명을 입력하세요

축과 노드에 숫자(0.0051 및 0.018)를 완전히 기록할 수 있는 신뢰할 수 있는 방법이 있습니까?

므웨:

\documentclass{article}
\usepackage[dvipsnames]{xcolor} %
\usepackage{pgfplots} %
\begin{document}
                \begin{tikzpicture}
                    \pgfplotsset{width=9 cm, height=9cm}
                    \begin{axis} [
                        symbolic x coords={0, last year, this year},
                        xtick={last year, this year},
%                        scaled ticks=false,
                        axis lines*=left, 
                        ymajorgrids = true, %shows the y grid
                        ymin=0,
%                        y tick label style={/pgf/number format/fixed},
                        bar width=12.5mm,
                        ybar=-1cm, 
                        enlarge x limits={abs=2.33cm},
                        nodes near coords,
                        every node near coord/.append style={color=black},
                    ]
                        \addplot [Red,fill=Red]
                        coordinates{ (last year,0.0051) (this year,0.018) } ;
                    \end{axis}
                \end{tikzpicture}
\end{document}

감사합니다

답변1

축과 막대 모두에 대한 숫자 형식을 설정하려면 다음을 사용할 수 있습니다.

\pgfkeys{/pgf/number format/fixed,/pgf/number format/precision=4}

코드

\documentclass{article}
\usepackage[dvipsnames]{xcolor} %
\usepackage{pgfplots} %
\pgfplotsset{compat=1.18}%<-- added
\begin{document}
\begin{tikzpicture}
  \pgfplotsset{width=9 cm, height=9cm}
  \pgfkeys{
    /pgf/number format/fixed,
    /pgf/number format/precision=4,
  }%<-- this line
  \begin{axis} [
      symbolic x coords={0, last year, this year},
      xtick={last year, this year},
      scaled ticks=false,
      axis lines*=left,
      ymajorgrids = true, %shows the y grid
      ymin=0,
      %  y tick label style={/pgf/number format/fixed,/pgf/number format/precision=4},
      bar width=12.5mm,
      ybar=-1cm,
      enlarge x limits={abs=2.33cm},
      nodes near coords,
      every node near coord/.append style={color=black},
    ]
    \addplot [Red,fill=Red]
    coordinates{ (last year,0.0051) (this year,0.018) } ;
  \end{axis}
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보