![在 pgfplots 中查找移位图和其他图的乘积](https://linux22.com/image/327092/%E5%9C%A8%20pgfplots%20%E4%B8%AD%E6%9F%A5%E6%89%BE%E7%A7%BB%E4%BD%8D%E5%9B%BE%E5%92%8C%E5%85%B6%E4%BB%96%E5%9B%BE%E7%9A%84%E4%B9%98%E7%A7%AF.png)
在 MWE 中,我将蓝色图向左移动。我现在如何绘制移动后的图(青色)和蓝色图的乘积?
这是我迄今为止的代码:
%\documentclass[varwidth]{standalone}
\documentclass[tikz]{standalone}
\usepackage{varwidth}
\usepackage{pgfplots,pgfplotstable, booktabs}
\usepackage{bm}
\usepgfplotslibrary{groupplots}
\usepackage{filecontents}
\usepackage{graphicx}
\usepackage{float}
\begin{filecontents*}{MAG.dat}
Iter Abs1 Abs2 x y
1, 0.9317521, 1.1849326, 1.6130556, 0.8022207
2, 1.8946202, 1.1228282, 1.8964566, -0.5353802
3, 1.5243302, 1.0372991, 1.4375012, 0.9719003
4, 1.5797030, 1.1346832, 1.8717142, 0.3138737
5, 1.8814457, 1.0529187, 2.0568468, -0.5509391
6, 2.0435003, 1.0470546, 2.0621956, -0.3565483
7, 2.0373926, 1.1215579, 2.1836100, 0.3360301
8, 1.9797077, 1.1632352, 1.8299063, 0.3871091
9, 1.9972528, 1.1952478, 1.8133509, -0.0867033
10, 1.8320176, 1.0625633, 1.0727495, 1.7256738
\end{filecontents*}
\pgfplotsset{compat=1.12}
\pgfplotsset{minor grid style={dotted,gray!90}}
\pgfplotsset{major grid style={gray!70!black},
every tick label/.append style={font=\scriptsize},
every axis plot/.append style={line width=0.8pt},
}
\newcommand{\bod}{MAG.dat}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{semilogxaxis}[width=14cm,height=10.2cm,
grid = both,
log ticks with fixed point,
every major grid/.style={gray, opacity=0.9},
title = {},
xlabel={\emph{\bfseries{Iteration}}},
ylabel={\emph{\bfseries{Temp}}},
no markers,
every axis plot/.append style={very thick},
legend style={at={(0,0)},anchor=south west},
legend cell align=left,
]
\addplot+ [red]table[x index=0,y index=1, col sep=comma] {\bod};
\addlegendentry{$\zeta = 0.3$};
\addplot+ [blue]table[x index=0,y index=3, col sep=comma] {\bod};
\addlegendentry{$\zeta = 0.5$};
\addplot+ [cyan]table[x index=0,y index=3, x expr=(\thisrowno{0}/2), col sep=comma] {\bod};
\addlegendentry{\emph{Shifted}};
\addlegendentry{\emph{Sum}}
\end{semilogxaxis}
\end{tikzpicture}
\end{figure}
\end{document}
答案1
结合蓝色和青色图意味着 x 和 y 值取自不同的数据行。但是,pgfplots
逐行处理它们。因此,在我看来,解析数据并在您选择的编程语言中计算所需函数并再次将结果作为数据文件提供要容易得多。