TikzとPGFPLOTSを使用したバープロット
Aug 17 2020
私はLaTeXを初めて使用します。ビーマードキュメントクラスで棒グラフを作成しようとしています。これが私が必要とするものです:

これが私がLaTeXで得たものです:

MWEについては、以下を参照してください。
これが私の質問です:
- LaTeXで同じように見える上記のチャートを複製するにはどうすればよいですか?私はtikマークと外側の境界線を保持するのが好きです。X軸のラベルとバーの分離にもっと興味があります。
- このグラフと同様のアスペクト比でグラフの幅を調整するにはどうすればよいですか(複数のグラフがあるため、グローバルオプションを指定したくない)、上記のグラフに対する棒の幅も調整しますか?
\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}
\usetheme{Boadilla}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\begin{document}
\begin{frame}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[ybar=25pt,ymin=0,ymax=150,]
\addplot[ybar,fill=blue, area legend] coordinates {(Rat,40)};
\addplot[ybar,fill=red, area legend] coordinates {(Hippopotamus,146)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
回答
1 Ross Aug 18 2020 at 02:37
TeX.SEへようこそ。これは次のとおりです。PGFPLOTS-異なる色の棒で棒グラフを作成します。さまざまな変更については、コードを参照してください。

\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}
\usetheme{Boadilla}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\begin{document}
\begin{frame}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
ybar,
xmin=0.5,xmax=2.5, %<-- added
ymin=0,
ymax=150,
area legend,
xtick={1,2}, % <-- added
xticklabels={Rat,Hippopotamus}, % <-- added
every axis plot/.append style={ % <-- added
bar width=.5,
bar shift=0pt,
fill}
]
\addplot[fill=blue] coordinates {(1,40)};
\addplot[fill=red] coordinates {(2,146)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}