我现在有四组向量,1,3带代表good,2,4代表bad,画出箱型图,并增加babel
- User
我现在有四组向量,1,3带代表good,2,4代表bad,画出箱型图,并增加babel
- Assistant
- (3,2,3,4) 代表good, bad, good, bad
- (1,2,3,4) 代表good, bad, good, bad
- (1,1,3,3) 代表good, good, bad, bad
- (2,2,4,4) 代表good, good, bad, bad
下面是箱型图,使用 babel 包来显示汉字。
\documentclass{article} \usepackage{pgfplots} \usepackage[english, chinese]{babel}
\begin{document}
\begin{tikzpicture} \begin{axis}[ height=8cm, width=10cm, ytick={1,2}, yticklabels={good,bad}, xlabel=Value, ylabel=Group, xlabel style={at={(0.5,1.2)},anchor=north}, ylabel style={at={(-0.15,0.5)},anchor=south}, title style={at={(0.5,1.3)},font=\bfseries}, boxplot/draw direction=y, x axis line style={opacity=0}, axis x line=none, ] \addplot+[boxplot] coordinates {(3,1) (2,2) (3,1) (4,2)}; \addplot+[boxplot] coordinates {(1,1) (2,2) (3,1) (4,2)}; \addplot+[boxplot] coordinates {(1,1) (1,2) (3,1) (3,2)}; \addplot+[boxplot] coordinates {(2,1) (2,2) (4,1) (4,2)}; \addplot[mark=*,only marks] coordinates {(3,1) (2,2) (3,1) (4,2) (1,1) (2,2) (3,1) (4,2) (1,1) (1,2) (3,1) (3,2) (2,1) (2,2) (4,1) (4,2)}; \end{axis}
\node[font=\bfseries] at (0.45cm,1cm) {1}; \node[font=\bfseries] at (0.45cm,2cm) {2}; \node[font=\bfseries] at (0.75cm,2.2cm) {good}; \node[font=\bfseries] at (0.75cm,0.8cm) {bad};
\end{tikzpicture}
\end{document}
输出结果:
注:简化了一下,只显示了每组向量中的四个数字。