pgfplots画地形图,我自己写的数据编译通不过

发布于 2021-04-03 21:00:14

说明文档里有几个例子,有个例子是是公式,还有一个有dat文件,超链接打不开,我自己写的数据通不过,求大佬帮忙看看数据格式应该是怎样的。
这里是pgfplots说明文档4.6.9小节的一个例子:

\documentclass[10pt]{standalone}

\usepackage{pgfplots}


\pgfplotsset{width=10cm,compat=newest}



\begin{document}

\begin{tikzpicture}
\begin{axis}[
title={$x \exp(-x^2-y^2)$},
domain=-2:2,
view={0}{90},
colorbar horizontal,
]
\addplot3 [
contour filled={
number=14,
},
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}


\end{document}

这里是我自己仿照写的,数据是我自己猜想的,只有xyz三列,不知道应该是怎样的。
main.tex

查看更多

关注者
0
被浏览
1.2k
越来越少
越来越少 2021-04-04
这家伙很懒,什么也没写!

参照手册的例子,把你的数据保存为文件 datafile.dat, 然后

\pgfplotstableread{datafile.dat}\datatable
\begin{tikzpicture}
\begin{axis}[
  view={160}{45},
  colorbar horizontal]
\addplot3 [
  mesh/ordering=y varies,
  mesh/rows=48,
  contour filled={
    number=40,
    handler/.style=smooth,
  }]
table {\datatable};
\end{axis}
\end{tikzpicture}

得到

37504f29de5bc781cd0e9ed39316a888.png

你的数据没有 scanline, 而且是先让 y 变量变化,再让 x 变量变化,所以需要参考以下选项

/pgfplots/mesh/rows
/pgfplots/mesh/cols
/pgfplots/mesh/ordering
/pgfplots/mesh/num points
3 个回答
LaTeXStudio
LaTeXStudio 2021-04-03
这家伙很懒,什么也没写!

这么多的数据,最好做个文件压缩传上来,另外,你原始的例子的链接提供下看看。

天地無用
天地無用 2021-04-04
这家伙很懒,什么也没写!

这个数据震荡有点大,总之去掉了contour filled就可以生成了,不是很了解是否一定需要contour filled
数据保存在了data.txt,这种大量的数据应该用文件保存起来,放在同一路径下

\documentclass[10pt]{standalone}
\usepackage{pgfplots}
\usepackage{siunitx}

\pgfplotsset{width=10cm,compat=newest}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[view = {120}{60}, colorbar horizontal, xlabel = $x$, ylabel = $y$, zlabel = $z$]
            \addplot3 [mesh/rows=2448, surf] table [x = x, y = y, z = z] {data.txt};
        \end{axis}
    \end{tikzpicture}
\end{document}

image.png

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览