需要提供 x 和 y 坐标和标题,在条形图的框架内,就像那里提到的第二幅图一样,我给出了如下所示的代码,但我得到的结果与第一幅图一样
\documentclass[12pt,a4paper]{report}
\usepackage{pgfplots}
\usepackage{color} %include colors
\usepackage{tikz}
\usepackage{graphicx}
% Define bar chart colors
%
\pgfplotsset{width=7cm,compat=1.8}
\begin{document}
\flushleft
{\color{blue}
\LARGE{Fault summary}\\
}
\flushleft
\begin{tikzpicture}
\begin{axis}
[
title = Names,
xbar stacked,
xmajorgrids = true,
bar width=0.5cm,
width=10cm,
height=7cm,
symbolic y coords={string,module},
ytick = data
]
\addplot[fill=blue] coordinates {(122,string) (63,module)};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
你可以让 pgfplots 轴消失
axis line style={draw=none}
然后添加另一个矩形,例如添加
background rectangle/.style={draw},
show background rectangle
从backgrounds
图书馆到的选项tikzpicture
。
\documentclass[12pt,a4paper]{report}
\usepackage{pgfplots}
%
\pgfplotsset{width=7cm,compat=1.17}
\usetikzlibrary{backgrounds}
\begin{document}
\flushleft
{\color{blue}
\LARGE{Fault summary}\\
}
\flushleft
\begin{tikzpicture}[background rectangle/.style={draw},
show background rectangle]
\begin{axis}
[axis line style={draw=none},
title = Names,
xbar stacked,
xmajorgrids = true,
bar width=0.5cm,
width=10cm,
height=7cm,
symbolic y coords={string,module},
ytick = data
]
\addplot[fill=blue] coordinates {(122,string) (63,module)};
\end{axis}
\end{tikzpicture}
\end{document}