![如何重用一个 addplot 表中的数据来在另一个轴上绘图?](https://linux22.com/image/293999/%E5%A6%82%E4%BD%95%E9%87%8D%E7%94%A8%E4%B8%80%E4%B8%AA%20addplot%20%E8%A1%A8%E4%B8%AD%E7%9A%84%E6%95%B0%E6%8D%AE%E6%9D%A5%E5%9C%A8%E5%8F%A6%E4%B8%80%E4%B8%AA%E8%BD%B4%E4%B8%8A%E7%BB%98%E5%9B%BE%EF%BC%9F.png)
有没有办法可以重复使用数据在另一个环境\addplot table
中进行绘图?axis
我想避免将数据放入单独的文件中。有没有办法引用表格中的数据进行绘图?
类似于:(无法编译)
\documentclass[12pt]{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
width=5cm,
height=5cm,
scale only axis,
enlargelimits=false,
line join=round
]
\addplot [color=white!70!black,solid,line width=0.5pt,forget plot]
table[name=tab1,row sep=crcr]{
1 -1 \\
2 -2 \\
3 3 \\
4 4 \\
};
\end{axis}
\begin{axis}[%
width=5cm,
height=5cm,
scale only axis,
enlargelimits=false,
line join=round
]
\addplot [color=red,solid,line width=0.8pt,forget plot]
table[name=tab1]{tab1};
\end{axis}
\end{tikzpicture}%
\end{document}
答案1
您可以使用pgfplotstable
工具读取它并将其保存在宏中
\documentclass[12pt]{article}
\usepackage{pgfplotstable}%<== Loads pgfplots anyway
\pgfplotsset{compat=1.10}
\pgfplotstableread[row sep=crcr]{
1 -1 \\
2 -2 \\
3 3 \\
4 4 \\
}\mytable
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
width=5cm,
height=5cm,
scale only axis,
enlargelimits=false,
line join=round
]
\addplot [color=black!30,solid,line width=1pt,forget plot]
table {\mytable};
\end{axis}
\begin{axis}[%
width=5cm,
height=5cm,
scale only axis,
enlargelimits=false,
line join=round,at={(7cm,0)}
]
\addplot [color=red,solid,line width=0.5pt,forget plot]
table {\mytable};
\end{axis}
\end{tikzpicture}%
\end{document}