Barplots กับ Tikz และ PGFPLOTS
Aug 17 2020
ฉันเพิ่งเริ่มใช้ LaTeX ฉันกำลังพยายามสร้างพล็อตแท่งด้วยคลาสเอกสาร beamer นี่คือสิ่งที่ฉันต้องการ:

นี่คือสิ่งที่ฉันได้รับจาก LaTeX:

โปรดดูด้านล่างสำหรับ MWE:
นี่คือคำถามของฉัน:
- ฉันจะทำซ้ำแผนภูมิด้านบนซึ่งคล้ายกันใน LaTeX ได้อย่างไร ฉันชอบที่จะรักษาเครื่องหมายติ๊กและเส้นขอบเอาไว้ ฉันสนใจป้ายชื่อแกน 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}