Pgfplots: 막대 차트 만들기

Pgfplots: 막대 차트 만들기

아래 그림은 구글독스에서 실시한 설문조사 결과입니다. LaTeX(뒷면)를 사용하여 유사한 막대 차트를 만들려고 하는데 지금까지 동일한 결과를 얻을 수 없습니다. 구글 문서

뒷면 위의 출력 수치는 지금까지 얻은 결과입니다. 내가 가진 문제는 다음과 같습니다

  1. 각 막대와 숫자 옆에 백분율을 표시하는 방법을 알 수 없었습니다(숫자만 표시됨).

  2. "영숫자가 아닌 기호(구두점, #, &, @ 등)"도 편집해야 했는데, 이를 유지하려고 하면 다른 3개 항목(숫자, 대문자, 소문자)과 해당 막대가 사라졌기 때문입니다.

  3. 나는 \documentclass[sigconf, nonacm, 12 pt, a4paper]{acmart}이중 열로 사용하고 있습니다. 두 열에 걸쳐 차트를 확장하려면 어떻게 해야 합니까? {Figure*}가 트릭을 수행해야 한다는 것을 이해하지만 여전히 차트가 약간 이상해 보입니다.

이것은 차트를 만드는 데 사용한 코드입니다.

\documentclass[sigconf, nonacm, 12 pt, a4paper]{acmart}
\usepackage{amsmath} 
\usepackage{pgf-pie}  
\usepackage{pgfplots} 
\pgfplotsset{compat=1.8} 
\usepackage{graphicx} 
\usepackage{xcolor} 
\usepackage{tikz}

\begin{document}

Text...

\begin{figure*} 
\centering
\caption{Characters Included in a Password}
\label{fig:Chara}
\begin{tikzpicture}
\begin{axis}[
xbar, xmin=0,
symbolic y coords={Nonalphanumeric symbols "punctuation marks etc.",Numbers, Uppercase Letters, Lowercase Letters},
ytick=data,
nodes near coords, nodes near coords align={horizontal},
]
\addplot coordinates {(64,Nonalphanumeric symbols "punctuation marks etc.") (85,Numbers) (62,Uppercase Letters) (83,Lowercase Letters)};
\end{axis}
\end{tikzpicture}
\end{figure*}

\bibliographystyle{ACM-Reference-Format}
\bibliography{sample}


\end{document}

내가 뭔가를 놓친 경우 알려주십시오.

답변1

조금 복잡할 수도 있지만 보기에는 더 좋습니다. ytick 레이블을 비우고 \node축 환경 외부를 사용하여 수동으로 추가합니다. 저는 이것을 수업 시간에 하지 않았기 acmart때문에 두 개의 열에서 행동을 테스트하지 않았습니다. 나는 그것이 잘 작동하기를 바랍니다. 그림 아래 캡션 위치도 변경합니다. 나는 이것이 표준이라고 생각합니다. 귀하의 경우가 아니라면 다시 옮기십시오. 코드는 다음과 같습니다.

\documentclass[sigconf,nonacm,12pt,a4paper]{acmart}
\usepackage{amsmath} 
\usepackage{pgf-pie}  
\usepackage{pgfplots} 
\pgfplotsset{compat=1.8} 
\usepackage{graphicx} 
\usepackage{xcolor} 
\usepackage{tikz}

\begin{document}
Text...

\begin{figure*}[ht]
\centering
\begin{tikzpicture}
\begin{axis}[%
width=0.81\textwidth, height=3.5in,
xbar, bar width=20pt,
xmin=0, xmax=100,
symbolic y coords={Nonalphanumeric, Numbers, Uppercase Letters, Lowercase Letters},
ytick=\empty,
xmajorgrids
]
\addplot [fill=blue!30,draw=blue] coordinates {(64,Nonalphanumeric)  (85,Numbers) (62,Uppercase Letters) (83,Lowercase Letters)}
node [minimum size=0pt,inner sep=0pt,right,pin={[font=\footnotesize,pin distance=0.3cm]0:64 (52.5\%)}] at (axis cs:64,Nonalphanumeric) {}
node [minimum size=0pt,inner sep=0pt,right,pin={[font=\footnotesize,pin distance=0.3cm]0:85 (69.7\%)}] at (axis cs:85,Numbers) {}
node [minimum size=0pt,inner sep=0pt,right,pin={[font=\footnotesize,pin distance=0.3cm]0:62 (50.8\%)}] at (axis cs:62,Uppercase Letters) {}
node [minimum size=0pt,inner sep=0pt,right,pin={[font=\footnotesize,pin distance=0.3cm]0:83 (68\%)}] at (axis cs:83,Lowercase Letters) {}
coordinate (symb) at (axis cs:0,Nonalphanumeric)
coordinate (num) at (axis cs:0,Numbers)
coordinate (uprcase) at (axis cs:0,Uppercase Letters)
coordinate (lwrcase) at (axis cs:0,Lowercase Letters);
\end{axis}
\node [font=\small,above left] at (symb) {Nonalphanumeric symbols};
\node [font=\small,left] at (symb) {(punctuation marks,};
\node [font=\small,below left] at (symb) {\#, \&, @, etc.)};
\node [font=\small,left] at (num) {Numbers};
\node [font=\small,left] at (uprcase) {Uppercase Letters};
\node [font=\small,left] at (lwrcase) {Lowercase Letters};
\end{tikzpicture}
\caption{Characters Included in a Password}
\label{fig:Chara}
\end{figure*}

\bibliographystyle{ACM-Reference-Format}
\bibliography{sample}
\end{document}

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

답변2

다른 답변을 추가해야 합니다. 이것은 훨씬 간단한 접근 방식입니다. 코드를 많이 줄이세요. 그리고 추가 \node명령이 필요하지 않습니다. 또한 축 프레임과 막대 색상을 Google 문서에 가깝게 만듭니다. 코드는 다음과 같습니다.

\documentclass[sigconf,nonacm,12pt,a4paper]{acmart}
\usepackage{amsmath} 
\usepackage{pgf-pie}  
\usepackage{pgfplots} 
\pgfplotsset{compat=1.8} 
\usepackage{graphicx} 
\usepackage{xcolor}
\usepackage{tikz}

\begin{document}
Text...
\begin{figure*}[ht]
\centering
\begin{tikzpicture}
\begin{axis}[%
width=0.85\textwidth, height=3.5in,
xbar, bar width=20pt,
xmin=0, xmax=100,
symbolic y coords={symb, num, uprcase, lwrcase},
ytick=data,
yticklabels={{Nonalphanumeric symbols (punctuation marks, \#, \&, @, etc.)},Numbers,Uppercase Letters,Lowercase Letters},
y tick label style={align=right,text width=3.2cm},
xtick={0,20,40,60,80,100},
xmajorgrids,
axis line style={lightgray},
major tick style={draw=none},
nodes near coords,
point meta=explicit symbolic,
node near coords style={font=\footnotesize,right=1em,pin={[pin distance=1em]180:}}
]
\addplot [fill={rgb:red,23;green,105;blue,170},draw=none] coordinates {(64,symb) [64 (52.5\%)]  (85,num) [85 (69.7\%)] (62,uprcase) [62 (50.8\%)] (83,lwrcase) [83 (68\%)]};
\draw [line width=1.5pt] (current axis.south west) -- (current axis.north west);
\end{axis}
\end{tikzpicture}
\caption{Characters Included in a Password}
\label{fig:Chara}
\end{figure*}

\bibliographystyle{ACM-Reference-Format}
\bibliography{sample}
\end{document}

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

관련 정보