有没有办法可以重复使用数据在另一个环境\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}