我正在尝试使用群图绘制图表,读者可以根据左侧 y 轴(频率)或右侧 y 轴(时间)读取曲线,但右侧 y 轴不遵循其ymin
和ymax
值,我不知道原因。这里出了什么问题?
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots,units}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group size=1 by 2,
horizontal sep=1.5cm,
ylabels at=edge left,
},
width=6.7cm, %7.3cm
height=6.7cm, %7.3cm
scale only axis,
xmin=0,xmax=100e-9,
ymin=3e6,ymax=13e6,
scaled x ticks=false,
change x base,
x SI prefix=nano,
change y base,
ylabel={Frequency},
y SI prefix={mega},
y unit=Hz,
enlargelimits=false,
grid=major,
]
\nextgroupplot[
xlabel={Time},
x unit=s,
only marks,
]
\addplot[blue,mark=square] coordinates {(3.33e-9,3.20e6) (5.e-8,6.03e6) (9.67e-8,3.18e6)};
\addplot[red,mark=triangle] coordinates {(3.33e-9,3.17e6) (5.e-8,6.03e6) (9.67e-8,3.19e6)};
\addplot[black,mark=o] coordinates {(3.33e-9,6.37e6) (5.e-8,1.21e7) (9.67e-8,6.37e6)};
\nextgroupplot[
axis y line=none,
axis x line*=bottom,
grid=none,
xlabel={Frequency},
x SI prefix=giga,
x unit=Hz,
xmin=0.5e9,
xmax=3.5e9,
xtick={0.5e9,1.1e9,1.7e9,2.3e9,2.9e9,3.5e9},
height=0.2cm,
]
\end{groupplot}
\begin{groupplot}[
group style={
group size=1 by 2,
},
width=6.7cm, %7.3cm
height=6.7cm, %7.3cm
scale only axis,
]
\nextgroupplot[
axis y line*=right,
axis x line=none,
grid=none,
ylabel={Time},
y SI prefix={nano},
y unit=s,
ymin=1e-10,ymax=4.3333e-10,
]
\end{groupplot}
\end{tikzpicture}
\end{document}
我在用着组图中的第二个 y 轴作为参考,上面的代码使用了虚假数据,只是为了生成一个最小的工作示例。
谢谢!
答案1
指定 x 范围,例如xmin=0,xmax=1
,它确实有效。默认情况下,axis
没有任何数据的 x 和 y 都覆盖 0 到 1 的范围。我不知道这是故意的、疏忽还是错误,但如果要使用默认值以外的值,则必须指定两个轴的范围。
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots,units}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group size=1 by 2,
horizontal sep=1.5cm,
ylabels at=edge left,
},
width=6.7cm, %7.3cm
height=6.7cm, %7.3cm
scale only axis,
xmin=0,xmax=100e-9,
ymin=3e6,ymax=13e6,
scaled x ticks=false,
change x base,
x SI prefix=nano,
change y base,
ylabel={Frequency},
y SI prefix={mega},
y unit=Hz,
enlargelimits=false,
grid=major,
]
\nextgroupplot[
xlabel={Time},
x unit=s,
only marks,
]
\addplot[blue,mark=square] coordinates {(3.33e-9,3.20e6) (5.e-8,6.03e6) (9.67e-8,3.18e6)};
\addplot[red,mark=triangle] coordinates {(3.33e-9,3.17e6) (5.e-8,6.03e6) (9.67e-8,3.19e6)};
\addplot[black,mark=o] coordinates {(3.33e-9,6.37e6) (5.e-8,1.21e7) (9.67e-8,6.37e6)};
\nextgroupplot[
axis y line=none,
axis x line*=bottom,
grid=none,
xlabel={Frequency},
x SI prefix=giga,
x unit=Hz,
xmin=0.5e9,
xmax=3.5e9,
xtick={0.5e9,1.1e9,1.7e9,2.3e9,2.9e9,3.5e9},
height=0.2cm,
]
\end{groupplot}
\begin{groupplot}[
group style={
group size=1 by 2,
},
width=6.7cm, %7.3cm
height=6.7cm, %7.3cm
scale only axis,
]
\nextgroupplot[
axis y line*=right,
axis x line=none,
grid=none,
ylabel={Time},
y SI prefix={nano},
y unit=s,
ymin=1e-10,ymax=4.3333e-10,
xmin=0,xmax=1 % <------------- added
]
\end{groupplot}
\end{tikzpicture}
\end{document}