我尝试使用 tikz 制作我的第一个图表,并且已经成功了很大一部分。
有两件事我没能完成:
- 使用文本标签而不是数字,我尝试使用注释,但弄清楚将它们放在哪里以及当发生变化时重新排列是很困难的......
- 改变图表的整体高度
我希望有人能够帮助我:)谢谢!
\documentclass[border=10pt]{standalone}
\usepackage{verbatim}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\begin{comment}
\end{comment}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
width=.9\textwidth,
bar width=.7\textwidth,
nodes near coords,
enlargelimits=0,
ylabel={Spannung in V},
symbolic x coords={tool1
%, tool2, tool3, tool4, tool5, tool6, tool7
},
xtick=data,
% x tick label style={rotate=45,anchor=east},
xtick style={draw=none},
xticklabel=\empty
]
\addplot+[ybar] plot coordinates {(tool1,0)};
\addplot+[ybar] plot coordinates {(tool1,20)};
\addplot+[ybar] plot coordinates {(tool1,4)};
\addplot+[ybar] plot coordinates {(tool1,12)};
\addplot+[ybar] plot coordinates {(tool1,12)};
\addplot+[ybar] plot coordinates {(tool1,4)};
\addplot+[ybar] plot coordinates {(tool1,2)};
\addplot+[ybar] plot coordinates {(tool1,4)};
\addplot+[ybar] plot coordinates {(tool1,2)};
\coordinate (A) at (5,20);
\coordinate (B) at (5,260);
\coordinate (C) at (5,80);
\coordinate (C) at (5,80);
\end{axis}
\node at (A) {test};
\node at (B) {test 2};
\end{tikzpicture}
\end{document}
答案1
您可以添加point meta=explicit symbolic
到axis
选项中,并将坐标写为(x,y) [text]
。要设置高度,请使用height=<length>
。
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.14} % with compat=1.9 or higher, the bar labels are placed in the center of the bar. 1.14 is the newest version at the moment
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
width=.9\textwidth,
height=\textwidth, % <-- added
bar width=.7\textwidth,
point meta=explicit symbolic, % <-- added
nodes near coords,
enlargelimits=0,
ylabel={Spannung in V},
symbolic x coords={tool1
%, tool2, tool3, tool4, tool5, tool6, tool7
},
xtick=data,
% x tick label style={rotate=45,anchor=east},
xtick style={draw=none},
xticklabel=\empty
]
\addplot+[ybar] plot coordinates {(tool1,0) [a]};
\addplot+[ybar] plot coordinates {(tool1,20) [b]};
\addplot+[ybar] plot coordinates {(tool1,4) [c]};
\addplot+[ybar] plot coordinates {(tool1,12) [d]};
\addplot+[ybar] plot coordinates {(tool1,12) [e]};
\addplot+[ybar] plot coordinates {(tool1,4) [f]};
\addplot+[ybar] plot coordinates {(tool1,2) [g]};
\addplot+[ybar] plot coordinates {(tool1,4) [h]};
\addplot+[ybar] plot coordinates {(tool1,2) [i]};
\end{axis}
\end{tikzpicture}
\end{document}