这是我刚刚画的图(正弦函数被外部数据取代)
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{through,calc,arrows,decorations.pathmorphing,backgrounds,positioning,fit}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\def\decalx{-0.8};
\def\decaly{-0.9};
\foreach \pas in {340,320,...,0}
{
\begin{scope}[xshift=\decalx*(340-\pas),yshift=\decaly*(340-\pas)]
\begin{axis}[xmax=600,ymin=-1,ymax=1,xtick=\empty,ytick=\empty,axis x line=middle,axis y line = left]
\addplot[fill=black!5!white,fill opacity=0.5, domain=0:360] expression {sin(\pas/100*\x)};
\end{axis}
\end{scope}
}
\begin{scope}[xshift=-2.8cm,yshift=-10.8cm]
\begin{axis}[,x={(-\decalx,-\decaly)},anchor=south west,xmin=0,xticklabel style={xshift=5},xtick={90,270},axis x line=middle,hide y axis]
\addplot[blue,samples=19,domain=0:360,error bars/.cd, y dir=minus,y fixed relative=1, error mark=none, error bar style={dotted}] {sin(x)};
\end{axis}
\end{scope}
\end{tikzpicture}
\end{figure}
\end{document}
问题是蓝色曲线是通过反复试验来放置的,取决于宽度、高度、y 最小值和最大值以及一堆其他东西......有什么办法可以提取前景图 x 轴的坐标,以便我可以从中绘制最终的蓝色图表???困难的部分可能是这个蓝色曲线是倾斜的......
到目前为止,我一直手工做这件事,而且我绝对可以继续做下去,只是我必须制作几十个这样的,而且用我的 300 点数据表来编译需要很长时间......
谢谢 !!!!
//编辑///
如果我需要 ymin 或 ymax 参数,Ant 的解决方案就不再起作用了……
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{through,calc,arrows,decorations.pathmorphing,backgrounds,positioning,fit}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\def\decalx{-0.6};
\def\decaly{-0.9};
\def\ymin{-0.5};
\foreach \pas in {340,320,...,0}
{
\begin{scope}[xshift=\decalx*(340-\pas),yshift=\decaly*(340-\pas)]
\begin{axis}[xmax=600,ymin=\ymin,ymax=1,xtick=\empty,ytick=\empty,axis x line=middle,axis y line = left]
\addplot[fill=black!5!white,fill opacity=0.5, domain=0:360] expression {sin(\pas/100*\x)};
\end{axis}
\end{scope}
}
\begin{scope}[xshift=\decalx*(340),yshift=\decaly*(340)]
\begin{axis}[xmax=600,ymin=\ymin,ymax=1,xtick=\empty,ytick=\empty,axis x line=middle,axis y line = left]
\addplot[fill=black!5!white,fill opacity=0.5, domain=0:360]
expression {0};
\node (start blue axis here) at (rel axis cs:1, 0) {};
\end{axis}
\end{scope}
\begin{axis}[at=(start blue axis here), x={(-\decalx,-\decaly)},anchor=south
west,xmin=0,xticklabel style={xshift=5},xtick={90,270},axis x
line=middle,hide y axis]
\addplot[blue,samples=19,domain=0:360,error bars/.cd, y
dir=minus,y fixed relative=1, error mark=none, error bar
style={dotted}] {sin(x)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
答案1
您可以在绘制最后一个直线轴时放置一个节点,以便将倾斜轴与其对齐。请参阅下面的示例的注释版本:
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{through,calc,arrows,decorations.pathmorphing,backgrounds,positioning,fit}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\def\decalx{-0.8};
\def\decaly{-0.9};
\foreach \pas in {340,320,...,20}
{
\begin{scope}[xshift=\decalx*(340-\pas),yshift=\decaly*(340-\pas)]
\begin{axis}[xmax=600,ymin=-1,ymax=1,xtick=\empty,ytick=\empty,axis x line=middle,axis y line = left]
\addplot[fill=black!5!white,fill opacity=0.5, domain=0:360] expression {sin(\pas/100*\x)};
\end{axis}
\end{scope}
}
所有这些都和以前一样,只是我将最后一个轴从循环中取出foreach
并将其添加到下面。
\begin{scope}[xshift=\decalx*(340),yshift=\decaly*(340)]
\begin{axis}[xmax=600,ymin=-1,ymax=1,xtick=\empty,ytick=\empty,axis x line=middle,axis y line = left]
\addplot[fill=black!5!white,fill opacity=0.5, domain=0:360]
expression {0};
\node (start blue axis here) at (axis cs:\pgfkeysvalueof{/pgfplots/xmax}, 0) {};
\end{axis}
\end{scope}
坐标系rel axis cs
可以很容易地将节点放置在倾斜轴应该开始的位置。现在我们只需使用键at
代替之前的范围:
\begin{axis}[at=(start blue axis here), x={(-\decalx,-\decaly)},
anchor=left of origin,
xmin=0,xticklabel style={xshift=5},xtick={90,270},axis x
line=middle,hide y axis]
\addplot[blue,samples=19,domain=0:360,error bars/.cd, y
dir=minus,y fixed relative=1, error mark=none, error bar
style={dotted}] {sin(x)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
...产生与原始示例相同的图表。
已编辑按 x 轴对齐而不是右下角,以便您可以更改 y 轴刻度,按照评论中的讨论。