
現在、ボックス プロットの x 軸の区切りを取得するにはどうしたらよいか困っています。少し関連のある tex.stackexchange の投稿を見ると、これは groupplot で実現できるはずだと推測していますが、コードを axis から groupplot に切り替えると、ボックス プロットが表示されません。
私が達成したいことを説明すると、次のようになります。
これについて何かアドバイスはありますか?
break と groupplot なしの動作コード:
\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
ytick=\empty,
xmin=0, xmax=4500,
xtick={0,500,1000,2500,4500},
axis x line=bottom,
axis line style={-},
axis y line=none,
enlargelimits=0.05,
height=4.0cm, width=14.0cm,
]
\addplot+[
boxplot prepared={
upper quartile=650,
lower quartile=30,
upper whisker=1400,
lower whisker=0,
median=80
},black,
] coordinates {
(0,2100)
(0,2300)
(0,2900)
(0,3400)
(0,3700)
(0,4200)
};
\end{axis}
\end{tikzpicture}
\end{document}
x 軸の区切りがあるボックス プロットのコードが機能しません:
\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group name=my fancy plots,
group size=2 by 1,
axis line style={-},
ytick=\empty,
},
width=14cm,
]
\nextgroupplot[
xtick={0,1000,2000,3000},
axis x discontinuity=parallel,
axis x line=bottom,
width=10cm]
\addplot[
boxplot prepared={
upper quartile=650,
lower quartile=30,
upper whisker=1400,
lower whisker=0,
median=80
},black,
] coordinates {
(0,2100)
(0,2300)
(0,2900)
(0,3400)
(0,3700)
(0,4200)
};
\nextgroupplot[xmin=9500,xmax=9750,
xtick={9500,9750},
axis x line=bottom,
width=2.0cm]
\addplot coordinates {(0,9600)};
\end{groupplot}
\end{tikzpicture}
\end{document}
ありがとう!
編集:
将来の参照用の動作コード:
\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group name=my fancy plots,
group size=2 by 1,
horizontal sep=3pt % added
},
% the following are added
scale only axis,
height=3cm,
ymin=0.5,ymax=1.5,
axis y line=none,
axis x line=bottom,
]
\nextgroupplot[
xmin=-100,
ymin=0.5,ymax=1.5,
xtick={0,1000,2000,3000},
width=10cm,
x axis line style={-{Bar[width=15pt]}}
]
\addplot[
mark = x , mark options = {mark color=black},
boxplot prepared={
upper quartile=650,
lower quartile=30,
upper whisker=1400,
lower whisker=0,
median=80
},black,
] coordinates {
(0,2100)
(0,2300)
(0,2900)
(0,3400)
(0,3700)
(0,4200)
};
\nextgroupplot[xmin=9300,xmax=9900,
xtick={9500,9750},
width=2.0cm,
x axis line style={{Bar[width=15pt]}-}
]
\addplot [
mark = x, mark options = {mark color=black}]
coordinates {(9600, 1)};
\end{groupplot}
\end{tikzpicture}
\end{document}
答え1
あなたの例に欠けている最初のものは です\usepgfplotslibrary{groupplots, statistics}
が、実際のドキュメントにはそれらが含まれていると思います。
コードにいくつか間違いがあります。
グループ プロットの軸の共通オプションは
group style
、 の内部ではなく外部に配置されます。したがって、axis line style={-}, ytick=\empty
を移動する必要があります。軸の幅のみを設定しますが、高さも設定しないとアスペクト比は一定のままになります。また、軸の幅と高さは、軸ラベルのためのスペースを確保するために、デフォルトで指定された長さより 45 ポイント小さく設定されることに注意してください。長
scale only axis
さが軸ボックス自体に適用されるようにするには、 を追加します。そうしないと、幅 2cm の軸が非常に小さくなってしまいます。2 番目の軸の座標プロットでは、x 値と y 値が入れ替わっています。
は
axis discontinuity
軸線の先頭に常に配置されますが、軸を 2 つに分割しているので、これは必要ありません。代わりに、軸線の矢印タイプを eg に変更してx axis line style={-|}
線を追加しました。(または\usetikzlibrary{arrows.meta}
、 を追加して使用しx axis line style={-{Bar[width=15pt]}}
、より長いバーを取得します。)
他にもいくつか調整を加えたと思いますが、それが主なものだったと思います。
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots, statistics}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group name=my fancy plots,
group size=2 by 1,
horizontal sep=3pt % added
},
% the following are added
scale only axis,
height=3cm,
ymin=0.5,ymax=1.5,
axis y line=none,
axis x line=bottom,
]
\nextgroupplot[
xmin=-100,
xtick={0,1000,2000,3000},
width=10cm,
x axis line style={-{Bar[width=15pt]}}
]
\addplot[
boxplot prepared={
upper quartile=650,
lower quartile=30,
upper whisker=1400,
lower whisker=0,
median=80
},black,
] coordinates {
(0,2100)
(0,2300)
(0,2900)
(0,3400)
(0,3700)
(0,4200)
};
\nextgroupplot[xmin=9350,xmax=9900,
xtick={9500,9750},
width=2.0cm,
x axis line style={{Bar[width=15pt]}-}
]
\addplot coordinates {(9600, 1)};
\end{groupplot}
\end{tikzpicture}
\end{document}