Pgfplots: 棒グラフの作成

Pgfplots: 棒グラフの作成

下の図は、Google ドキュメントからの調査結果です。LaTeX (overleaf) を使用して同様の棒グラフを作成しようとしていますが、これまでのところ同じ結果を得ることができていません。 Googleドキュメント

裏面 上記の出力図は、私がこれまでに得た結果です。私が抱えている問題は次のとおりです。

  1. 各バーと数字の横にパーセンテージを表示する方法がわかりませんでした (数字のみが表示されます)。

  2. 「英数字以外の記号(句読点、#、&、@ など)」も編集する必要がありました。これを保持しようとすると、他の 3 つのエントリ(数字、大文字、小文字)とそのバーが消えてしまったためです。

  3. 2 列表示にしています\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 ラベルを空にして、\nodeaxis 環境の外側を使用して手動で追加します。acmartクラスではこれを実行しなかったため、2 列での動作はテストしていません。うまくいくことを願っています。また、図の下のキャプションの位置を変更します。これは標準だと思います。そうでない場合は、元に戻してください。コードは次のとおりです。

\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}

ここに画像の説明を入力してください

関連情報