막대 그래프에서 각 데이터 세트를 분리하는 문제

막대 그래프에서 각 데이터 세트를 분리하는 문제

일부 데이터를 비교하기 위해 막대 그래프를 사용하고 싶습니다. 코드를 입력했을 때 결과는 내가 원하는 것과 달랐습니다. 각 막대 세트를 명확하게 구분하고 싶습니다. 내가 원하는 두 번째 요점은 내가 입력한 대로 숫자가 표시되지만 int 출력에서는 숫자가 반올림된다는 것입니다. 이러한 문제를 어떻게 해결할 수 있습니까?

여기 내 코드가 있습니다

\documentclass{standalone}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar=.5cm,
    x tick label style={rotate=90},
    enlarge x limits=0.2,
    legend style={at={(0.5,-0.15)},
    anchor=north,legend columns=-1},
    bar width = 0.2 cm,
    symbolic x coords=        {4g,6g,8g,10g,2gamma,3gamma,4gamma,5gamma,6gamma,7gamma,0beta},
    xtick=data,
   xticklabels={$ 4_g $, $ 6_g $, $ 8_g $, $ 10_g $, $ 2_\gamma $, $ 3_\gamma     $, $ 4_\gamma $, $ 5_\gamma $, $ 6_\gamma $, $ 7_\gamma $, $ 0_\beta $},
    nodes near coords,
    nodes near coords align={vertical},
    ]
\addplot coordinates {(4g, 2.337) (6g, 3.949) (8g, 5.815) (10g, 7.924) (2gamma, 1.830) (3gamma, 2.581) (4gamma, 4.379) (5gamma, 4.590) (6gamma, 6.983) (7gamma, 6.792) (0beta, 3.790)};

\addplot coordinates {(4g, 2.479) (6g, 4.314) (8g, 6.377) (10g, 8.624) (2gamma, 1.935) (3gamma, 2.91) (4gamma, 3.795) (5gamma, 4.682) (6gamma, 5.905) (7gamma, 6.677) (0beta, 3.776)};

\addplot coordinates {(4g, 2.350) (6g, 3.984) (8g, 5.877 ) (10g, 8.019) (2gamma, 1.837) (3gamma, 2.597) (4gamma, 4.420) (5gamma, 4.634) (6gamma, 7.063) (7gamma, 6.869) (0beta, 3.913)};

\legend{used,understood,not understood}
\end{axis}
\end{tikzpicture}
\end{document}

많은 감사를 드립니다.

답변1

해당 크기의 플롯이 편안하게 들어갈 수 있는 것보다 더 많은 데이터가 있습니다. 상황에 맞게 플롯을 더 넓게 만들고 해당 교대근무를 추가할 수도 있습니다. 정밀도를 높이면 반올림이 발생하지 않습니다. 노드가 너무 겹치지 않도록 회전시켰습니다.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16,width=12cm}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar=.8cm,
    x tick label style={rotate=90},
    %enlarge x limits=0.2,
    legend style={at={(0.5,-0.15)},
    anchor=north,legend columns=-1},
    bar width = 0.2 cm,
    symbolic x coords=        {4g,6g,8g,10g,2gamma,3gamma,4gamma,5gamma,6gamma,7gamma,0beta},
    xtick=data,
   xticklabels={$ 4_g $, $ 6_g $, $ 8_g $, $ 10_g $, $ 2_\gamma $, $ 3_\gamma     $, $ 4_\gamma $, $ 5_\gamma $, $ 6_\gamma $, $ 7_\gamma $, $ 0_\beta $},
    nodes near coords={\pgfmathprintnumber[precision=3]{\pgfplotspointmeta}},
    nodes near coords align={vertical},
    nodes near coords style={rotate=90,anchor=west}
    ]
\addplot+[bar shift = -0.25cm] coordinates {(4g, 2.337) (6g, 3.949) (8g, 5.815) (10g, 7.924) (2gamma, 1.830) (3gamma, 2.581) (4gamma, 4.379) (5gamma, 4.590) (6gamma, 6.983) (7gamma, 6.792) (0beta, 3.790)};

\addplot+[bar shift = -0cm] coordinates {(4g, 2.479) (6g, 4.314) (8g, 6.377) (10g, 8.624) (2gamma, 1.935) (3gamma, 2.91) (4gamma, 3.795) (5gamma, 4.682) (6gamma, 5.905) (7gamma, 6.677) (0beta, 3.776)};

\addplot+[bar shift = 0.25cm] coordinates {(4g, 2.350) (6g, 3.984) (8g, 5.877 ) (10g, 8.019) (2gamma, 1.837) (3gamma, 2.597) (4gamma, 4.420) (5gamma, 4.634) (6gamma, 7.063) (7gamma, 6.869) (0beta, 3.913)};

\legend{used,understood,not understood}
\end{axis}
\end{tikzpicture}
\end{document}

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

답변2

pgfplotstable(운동을 위해 ...) 를 사용하는 대안

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.16}

\begin{document}
    \begin{tikzpicture}
    \pgfplotstableread{% table with diagram's data
X           Y1      Y2      Y3
$4_g$       2.337   2.479   2.350
$6_g$       3.949   4.314   3.984
$8_g$       5.815   6.377   5.877
$10_g$      7.924   8.624   8.019
$2_\gamma$  1.830   1.935   1.837
$3_\gamma$  2.581   2.91    2.597
$4_\gamma$  4.379   3.795   4.420
$5_\gamma$  4.590   4.682   4.634
$6_\gamma$  6.983   5.905   7.063
$7_\gamma$  6.792   6.677   6.869
$0_\beta$   3.790   3.776   3.913
    }\mydata

\begin{axis}[width=99mm,
ylabel=Population,
legend style={legend columns=-1,
              font=\footnotesize,
              /tikz/every even column/.append style={column sep=2mm},
               anchor=north,
              at={(0.5,-0.1)},
              },
ybar=0.5mm,     % distance between bars (shift bar)
bar width=2mm,  % width of bars
    nodes near coords={\pgfmathprintnumber[precision=3]{\pgfplotspointmeta}},
    nodes near coords style={font=\scriptsize, rotate=90, anchor=west},
    nodes near coords align={vertical},
    ymin=0, ymax=10,
    ytick={0,...,10},
    %
    xtick=data,
    xticklabels from table = {\mydata}{X},
    scale only axis,
    ]
\addplot table[x expr=\coordindex,y index=1] {\mydata};
\addplot table[x expr=\coordindex,y index=2] {\mydata};
\addplot table[x expr=\coordindex,y index=3] {\mydata};

\legend{used,understood,not understood}
\end{axis}
    \end{tikzpicture}
\end{document}

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

관련 정보