我有
成功使用 gnuplot 将 Matlab 生成的列表数据绘制为 tikz-pgf 中的轮廓。数据排列如下
1,-6.2832,-6.2832,0.74038
2,-6.2832,-6.1563,0.74997
3,-6.2832,-6.0293,0.75982
4,-6.2832,-5.9024,0.76986
.......
addplot 适用于
\addplot3[mesh/rows=100,mesh/num points=10000,contour gnuplot={
number=24,
% cdata should not be affected by z filter:
output point meta=rawz,
labels=false,
}] table [x index={1}, y index={2}, z index={3}] {\datatable};
问题:
我想要使用矩阵数据做同样的事情,因为这样运行起来似乎更快。我该怎么做呢?我该如何格式化数据?这里不是最小的平均能量损失:
\documentclass{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz,pgfplots,pgfplotstable,pgffor,pgfmath,tikz-3dplot}
%===================================================
\usetikzlibrary{positioning,plotmarks,pgfplots.colormaps,external,3d,calc,arrows}
\usetikzlibrary{decorations,decorations.pathmorphing,decorations.pathreplacing}
\usetikzlibrary{shapes,arrows}
\tikzexternalize[mode=convert with system call,shell escape=-enable-write18]
%===================================================
%==== Tikz & PGF Camera alignment macro ============
% Style to set TikZ camera angle, like PGFPlots `view`
\tikzset{viewport/.style 2 args={
x={({cos(-#1)*1cm},{sin(-#1)*sin(#2)*1cm})},
y={({-sin(-#1)*1cm},{cos(-#1)*sin(#2)*1cm})},
z={(0,{cos(#2)*1cm})}
}}
%===================================================
%Define standard arrow tip
\tikzset{>=stealth',}
% Color Map
\pgfplotsset{
colormap={colormap2}{
color(0cm)=(blue!70!black);
color(1cm)=(cyan!60!black)
}
}
%==== Externalisation ==============================
\makeatletter
\newcommand{\useexternalfile}[2][Tikz] % \useexternalfile[Folder]{Filename}
{
\tikzsetnextfilename{#2-output}
\input{#1/#2.tikz}
}
\makeatother
%===================================================
\begin{document}
\begin{tikzpicture}
\pgfplotstableread[col sep = comma]{Matrix.csv}\datatable
\begin{axis}
[
view={0}{90},
scale only axis,
colormap name={colormap2},
ticks=none
]
\addplot3[surf, mesh/rows=100, mesh/cols=100] table {\datatable};
\end{axis}
\end{tikzpicture}
\end{document}
使用这个,我得到了错误
Package pgfplots Error: the arguments of [mesh/rows=100,mesh/cols=100] assume 10000 points, but I got actually N = 100 points!
The data matrix appears to be incomplete or overcomplete!?
我的矩阵.csv形式为
0.74038,0.74228,0.744,0.74549,0.74672,......,0.27529
0.74997,0.75246,0.75477,0.75685,0.75867,.....,0.26786
.....
即每行有100个数据点,一共有100行。每行数据以逗号分隔,每行以换行符分隔。
答案1
您的原始输入是将矩阵数据传达给 pgfplots 的唯一且正确支持的方式,即每行提供一个矩阵单元。
目前不支持以矩阵形式提供 Z 数据的格式,其中输入文件中的每一行都是整个矩阵的一行。