![pgfplots:隐藏 groupplot 中的标签](https://linux22.com/image/406560/pgfplots%EF%BC%9A%E9%9A%90%E8%97%8F%20groupplot%20%E4%B8%AD%E7%9A%84%E6%A0%87%E7%AD%BE.png)
在以下 MWE 中,Y 标签与左侧图重叠,因此看起来很糟糕。我想将其抑制(从而只为 LHS 图保留 Y 标签)。如何实现?
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}
\begin{document}
\pgfplotsset{
ylabel right/.style={
after end axis/.append code={
\node [rotate=90, anchor=north] at (rel axis cs:1,0.5) {#1};
}
}
}
\begin{tikzpicture}
\begin{groupplot}[
group style={group size=2 by 1},
legend cell align=right,
legend pos=north east,
ylabel={Y label},
xlabel={X label},
]
\nextgroupplot
\addplot+ [
scatter/classes={
a={mark=square,black},
b={mark=square*,black},
c={mark=10-pointed star,draw=black},
d={mark=*,black},
e={mark=oplus,draw=black},
f={mark=otimes,draw=black},
g={mark=+,black},
h={mark=star,black}
},
scatter, only marks,
scatter src=explicit symbolic,
]
table [meta=label] {
x y label
2.7 3396 a
6.2 1945 b
27.3 28 c
12.6 58 d
0.58 789 e
0.73 417 f
0.73 985 g
0.81 741 h
};
\legend{a,b,c,d,e,f,g,h}
\draw[dashed,thick] (axis cs:0,0) rectangle (axis cs:0.9,990);
\nextgroupplot[xmin=0.4,xmax=1,ymin=400,ymax=1000]
\addplot+ [
scatter/classes={
e={mark=oplus,draw=black},
f={mark=otimes,draw=black},
g={mark=+,black},
h={mark=star,black}
},
scatter, only marks,
scatter src=explicit symbolic,
]
table [meta=label] {
x y label
0.58 789 e
0.73 417 f
0.73 985 g
0.81 741 h
};
\end{groupplot}
\node (title) at ($(group c1r1.center)!0.5!(group c2r1.center)+(0,4cm)$) {Some title};
\draw[thick,blue,->,shorten >=2pt,shorten <=2pt]
(group c1r1.east) -- (group c2r1.west);
\end{tikzpicture}
\end{document}
答案1
您添加ylabels at=edge left
以下group style
选项:
\documentclass{article}
\usepackage{pgfplots}% loads tikz automatically
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}
\begin{document}
\pgfplotsset{
ylabel right/.style={
after end axis/.append code={
\node [rotate=90, anchor=north] at (rel axis cs:1,0.5) {#1};
}
}
}
\begin{tikzpicture}
\begin{groupplot}[
group style={group size=2 by 1,ylabels at=edge left},% <- changed
legend cell align=right,
legend pos=north east,
ylabel={Y label},
xlabel={X label}
]
\nextgroupplot
\addplot+ [
scatter/classes={
a={mark=square,black},
b={mark=square*,black},
c={mark=10-pointed star,draw=black},
d={mark=*,black},
e={mark=oplus,draw=black},
f={mark=otimes,draw=black},
g={mark=+,black},
h={mark=star,black}
},
scatter, only marks,
scatter src=explicit symbolic,
]
table [meta=label] {
x y label
2.7 3396 a
6.2 1945 b
27.3 28 c
12.6 58 d
0.58 789 e
0.73 417 f
0.73 985 g
0.81 741 h
};
\legend{a,b,c,d,e,f,g,h}
\draw[dashed,thick] (axis cs:0,0) rectangle (axis cs:0.9,990);
\nextgroupplot[xmin=0.4,xmax=1,ymin=400,ymax=1000]
\addplot+ [
scatter/classes={
e={mark=oplus,draw=black},
f={mark=otimes,draw=black},
g={mark=+,black},
h={mark=star,black}
},
scatter, only marks,
scatter src=explicit symbolic,
]
table [meta=label] {
x y label
0.58 789 e
0.73 417 f
0.73 985 g
0.81 741 h
};
\end{groupplot}
\node (title) at ($(group c1r1.center)!0.5!(group c2r1.center)+(0,4cm)$) {Some title};
\draw[thick,blue,->,shorten >=2pt,shorten <=2pt]
(group c1r1.east) -- (group c2r1.west);
\end{tikzpicture}
\end{document}