请考虑以下 MWE。除了xstick
底部 x 轴(或主 x 轴)的,我还想extra tick
在顶部 x 轴(或次级 x 轴)添加。
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots,pgfplotstable}
\usetikzlibrary{pgfplots,groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group size=2 by 2,
xlabels at=edge bottom,
ylabels at=edge left,
vertical sep= 1.5cm,
horizontal sep= 2cm,
every axis y label/.style={at={(ticklabel cs:0.5)},rotate=90,anchor=near ticklabel}
},
footnotesize,
xlabel=xlabel,
ylabel=very long label
,xtick={42,44,46,48}
,extra x ticks={41}
,extra x tick style={pos=right, grid=major,
tick label style={pos=left,font=\footnotesize,anchor=north}},
extra x tick labels={VLP},
]
\nextgroupplot[title=\#1]
\addplot[dashed] coordinates{(42, 255) (43, 1584) (44, 1296) (45, 432) (46, 972) (47, 540) (48, 1104) (49, 0)};
\addplot[blue] coordinates{(41, 608) (42, 608) (43, 1068) (44, 1068) (45, 870) (46, 654) (47,654) (48, 654) (49, 0)};
\nextgroupplot[title=\#2]
\addplot[dashed] coordinates{(42, 400) (43, 400) (44, 0) (45, 400) (46, 0) (47, 0) (48, 0) (49, 0)};
\addplot[blue] coordinates{(41, 267) (42, 267) (43, 267) (44, 200) (45, 200) (46, 0) (47, 0) (48, 0) (49, 0)};
\nextgroupplot[title=\#3]
\addplot[dashed] coordinates{(42, 1800) (43, 2100) (44, 1800) (45, 900) (46, 2100) (47, 2100) (48, 2100) (49, 0)};
\addplot[blue] coordinates{(41, 1613) (42, 1613) (43, 1613) (44, 1613) (45, 1613) (46, 1613) (47, 1613) (48,1613) (49, 0)};
\nextgroupplot[title=\#4]
\addplot[dashed] coordinates{(42, 6800) (43, 2800) (44, 2800) (45, 2800) (46, 2000) (47, 2800) (48, 0) (49, 0)};
\addplot[blue] coordinates{(41, 3600) (42, 3600) (43, 2799) (44, 2789) (45, 2708) (46, 2254) (47, 2254) (48, 0) (49, 0)};
\end{groupplot}
\end{tikzpicture}
\end{document}
答案1
我不知道您的文档如何与那个奇怪的序言 ( \usetikzlibrary{pgfplots}
?) 一起工作。无论如何,您必须将和都设置tick pos
为ticklabel pos
,right
然后无需设置锚点。
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.6, /pgf/number format/.cd,
1000 sep={\,}, min exponent for 1000 sep=4}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group size=2 by 2,
xlabels at=edge bottom,
ylabels at=edge left,
vertical sep=1.5cm,
horizontal sep=2cm,
every axis ylabel/.append style={at={(ticklabel cs:0.5)}, rotate=90,
anchor=near ticklabel}},
width=0.46\textwidth,
xlabel={xlabel},
ylabel={very long label},
xtick={42,44,46,48},
extra x ticks={41},
extra x tick labels={VLP},
extra x tick style={tick pos=right, grid=major, ticklabel pos=right,
tick label style={font=\footnotesize}}
]
\nextgroupplot[title=\#1]
\addplot[dashed] coordinates{(42, 255) (43, 1584) (44, 1296) (45, 432)
(46, 972) (47, 540) (48, 1104) (49, 0)};
\addplot[blue] coordinates{(41, 608) (42, 608) (43, 1068) (44, 1068)
(45, 870) (46, 654) (47,654) (48, 654) (49, 0)};
\nextgroupplot[title=\#2]
\addplot[dashed] coordinates{(42, 400) (43, 400) (44, 0) (45, 400)
(46, 0) (47, 0) (48, 0) (49, 0)};
\addplot[blue] coordinates{(41, 267) (42, 267) (43, 267) (44, 200)
(45, 200) (46, 0) (47, 0) (48, 0) (49, 0)};
\nextgroupplot[title=\#3]
\addplot[dashed] coordinates{(42, 1800) (43, 2100) (44, 1800) (45, 900)
(46, 2100) (47, 2100) (48, 2100) (49, 0)};
\addplot[blue] coordinates{(41, 1613) (42, 1613) (43, 1613) (44, 1613)
(45, 1613) (46, 1613) (47, 1613) (48,1613) (49, 0)};
\nextgroupplot[title=\#4]
\addplot[dashed] coordinates{(42, 6800) (43, 2800) (44, 2800) (45, 2800)
(46, 2000) (47, 2800) (48, 0) (49, 0)};
\addplot[blue] coordinates{(41, 3600) (42, 3600) (43, 2799) (44, 2789)
(45, 2708) (46, 2254) (47, 2254) (48, 0) (49, 0)};
\end{groupplot}
\end{tikzpicture}
\end{document}