如何在 pgfplots 中使用外部文件表重现隐式冲浪图?

如何在 pgfplots 中使用外部文件表重现隐式冲浪图?

我可以用隐式定义绘制一个与我想要的非常相似的函数:

\addplot3[surf] ({x*cos(y)},{x*sin(y)},{x});

但是当我尝试对外部文件执行相同操作时,表面看起来很破损:

\addplot3[surf] table[x expr={\thisrowno{0}*cos(\thisrowno{1})},
                      y expr={\thisrowno{0}*sin(\thisrowno{1})},
                      z expr={\thisrowno{0}}] {func.dat};

左:好,右:坏 在此处输入图片描述

如何使用外部文件获取相同的图?我可以以某种方式重新排列表格吗?还是应该手动添加每个补丁?

完整示例:

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}
\pgfplotsset{width=10cm,compat=1.11}

\pgfplotsset{
  defaultaxis/.style={
    domain=-1.0:1.0, y domain=0:360,
    samples=5, samples y=19,
    enlargelimits=false,
    view={32}{17},
    z post scale=1.5,
    xtick=\empty, ytick=\empty, ztick=\empty,
    z buffer=sort,
    shader=faceted, faceted color=black,
    patch type=biquadratic, patch type sampling,
    point meta={sqrt(x^2+y^2)},
    colormap={graywhite}{color(0cm)=(black!80) color(1cm)=(black!20)},
    mesh/interior colormap={bluewhite}{color(0cm)=(blue!50!black) color(1cm)=(blue!50!white)},
    mesh/interior colormap thresh=-0.01,
  },
}

\begin{document}

\begin{tikzpicture}
\begin{axis}[defaultaxis]

\addplot3[surf,fill opacity=0.8] ({x*cos(y)},{x*sin(y)},{x});

\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[defaultaxis]

\addplot3[surf,fill opacity=0.8]
table[x expr={\thisrowno{0}*cos(\thisrowno{1})},
      y expr={\thisrowno{0}*sin(\thisrowno{1})},
      z expr={\thisrowno{0}}]
{func.dat};

\end{axis}
\end{tikzpicture}

\end{document}

函数数据表

-1.00 360.0
-1.00 340.0
-1.00 320.0
-1.00 300.0
-1.00 280.0
-1.00 260.0
-1.00 240.0
-1.00 220.0
-1.00 200.0
-1.00 180.0
-1.00 160.0
-1.00 140.0
-1.00 120.0
-1.00 100.0
-1.00  80.0
-1.00  60.0
-1.00  40.0
-1.00  20.0
-1.00   0.0
           
-0.50 360.0
-0.50 340.0
-0.50 320.0
-0.50 300.0
-0.50 280.0
-0.50 260.0
-0.50 240.0
-0.50 220.0
-0.50 200.0
-0.50 180.0
-0.50 160.0
-0.50 140.0
-0.50 120.0
-0.50 100.0
-0.50  80.0
-0.50  60.0
-0.50  40.0
-0.50  20.0
-0.50   0.0
           
-0.00 360.0
-0.00 340.0
-0.00 320.0
-0.00 300.0
-0.00 280.0
-0.00 260.0
-0.00 240.0
-0.00 220.0
-0.00 200.0
-0.00 180.0
-0.00 160.0
-0.00 140.0
-0.00 120.0
-0.00 100.0
-0.00  80.0
-0.00  60.0
-0.00  40.0
-0.00  20.0
-0.00   0.0
           
 0.50 360.0
 0.50 340.0
 0.50 320.0
 0.50 300.0
 0.50 280.0
 0.50 260.0
 0.50 240.0
 0.50 220.0
 0.50 200.0
 0.50 180.0
 0.50 160.0
 0.50 140.0
 0.50 120.0
 0.50 100.0
 0.50  80.0
 0.50  60.0
 0.50  40.0
 0.50  20.0
 0.50   0.0
           
 1.00 360.0
 1.00 340.0
 1.00 320.0
 1.00 300.0
 1.00 280.0
 1.00 260.0
 1.00 240.0
 1.00 220.0
 1.00 200.0
 1.00 180.0
 1.00 160.0
 1.00 140.0
 1.00 120.0
 1.00 100.0
 1.00  80.0
 1.00  60.0
 1.00  40.0
 1.00  20.0
 1.00   0.0

答案1

要回答我自己的问题,patch type=biquadratic需要一个可以在任意点进行评估的函数,或者至少手动指定角和中间点

因此,我需要(a)将表中的采样数加倍(这是隐式函数在后台执行的操作)和(b)列出每个补丁的所有点patch table

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}
\pgfplotsset{width=10cm,compat=1.11}

\pgfplotsset{
  defaultaxis/.style={
    domain=-1.0:1.0, y domain=0:360,
    samples=5, samples y=19,
    enlargelimits=false,
    view={32}{17},
    z post scale=1.5,
    xtick=\empty, ytick=\empty, ztick=\empty,
    z buffer=sort,
    shader=faceted, faceted color=black,
    patch type=biquadratic, patch type sampling,
    point meta={sqrt(x^2+y^2)},
    colormap={graywhite}{color(0cm)=(black!80) color(1cm)=(black!20)},
    mesh/interior colormap={bluewhite}{color(0cm)=(blue!50!black) color(1cm)=(blue!50!white)},
    mesh/interior colormap thresh=-0.01,
  },
}

\begin{document}

\begin{tikzpicture}
\begin{axis}[defaultaxis]

\addplot3[surf,fill opacity=0.8] ({x*cos(y)},{x*sin(y)},{x});

\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[defaultaxis]

\addplot3[surf,fill opacity=0.8,patch table={func.tab}]
table[x expr={\thisrowno{0}*cos(\thisrowno{1})},
      y expr={\thisrowno{0}*sin(\thisrowno{1})},
      z expr={\thisrowno{0}}]
{func.dat};

\end{axis}
\end{tikzpicture}

\end{document}

函数数据表

-1.00 360.0
-1.00 350.0
-1.00 340.0
-1.00 330.0
-1.00 320.0
-1.00 310.0
-1.00 300.0
-1.00 290.0
-1.00 280.0
-1.00 270.0
-1.00 260.0
-1.00 250.0
-1.00 240.0
-1.00 230.0
-1.00 220.0
-1.00 210.0
-1.00 200.0
-1.00 190.0
-1.00 180.0
-1.00 170.0
-1.00 160.0
-1.00 150.0
-1.00 140.0
-1.00 130.0
-1.00 120.0
-1.00 110.0
-1.00 100.0
-1.00  90.0
-1.00  80.0
-1.00  70.0
-1.00  60.0
-1.00  50.0
-1.00  40.0
-1.00  30.0
-1.00  20.0
-1.00  10.0
-1.00   0.0

-0.75 360.0
-0.75 350.0
-0.75 340.0
-0.75 330.0
-0.75 320.0
-0.75 310.0
-0.75 300.0
-0.75 290.0
-0.75 280.0
-0.75 270.0
-0.75 260.0
-0.75 250.0
-0.75 240.0
-0.75 230.0
-0.75 220.0
-0.75 210.0
-0.75 200.0
-0.75 190.0
-0.75 180.0
-0.75 170.0
-0.75 160.0
-0.75 150.0
-0.75 140.0
-0.75 130.0
-0.75 120.0
-0.75 110.0
-0.75 100.0
-0.75  90.0
-0.75  80.0
-0.75  70.0
-0.75  60.0
-0.75  50.0
-0.75  40.0
-0.75  30.0
-0.75  20.0
-0.75  10.0
-0.75   0.0

-0.50 360.0
-0.50 350.0
-0.50 340.0
-0.50 330.0
-0.50 320.0
-0.50 310.0
-0.50 300.0
-0.50 290.0
-0.50 280.0
-0.50 270.0
-0.50 260.0
-0.50 250.0
-0.50 240.0
-0.50 230.0
-0.50 220.0
-0.50 210.0
-0.50 200.0
-0.50 190.0
-0.50 180.0
-0.50 170.0
-0.50 160.0
-0.50 150.0
-0.50 140.0
-0.50 130.0
-0.50 120.0
-0.50 110.0
-0.50 100.0
-0.50  90.0
-0.50  80.0
-0.50  70.0
-0.50  60.0
-0.50  50.0
-0.50  40.0
-0.50  30.0
-0.50  20.0
-0.50  10.0
-0.50   0.0

-0.25 360.0
-0.25 350.0
-0.25 340.0
-0.25 330.0
-0.25 320.0
-0.25 310.0
-0.25 300.0
-0.25 290.0
-0.25 280.0
-0.25 270.0
-0.25 260.0
-0.25 250.0
-0.25 240.0
-0.25 230.0
-0.25 220.0
-0.25 210.0
-0.25 200.0
-0.25 190.0
-0.25 180.0
-0.25 170.0
-0.25 160.0
-0.25 150.0
-0.25 140.0
-0.25 130.0
-0.25 120.0
-0.25 110.0
-0.25 100.0
-0.25  90.0
-0.25  80.0
-0.25  70.0
-0.25  60.0
-0.25  50.0
-0.25  40.0
-0.25  30.0
-0.25  20.0
-0.25  10.0
-0.25   0.0

 0.00 360.0
 0.00 350.0
 0.00 340.0
 0.00 330.0
 0.00 320.0
 0.00 310.0
 0.00 300.0
 0.00 290.0
 0.00 280.0
 0.00 270.0
 0.00 260.0
 0.00 250.0
 0.00 240.0
 0.00 230.0
 0.00 220.0
 0.00 210.0
 0.00 200.0
 0.00 190.0
 0.00 180.0
 0.00 170.0
 0.00 160.0
 0.00 150.0
 0.00 140.0
 0.00 130.0
 0.00 120.0
 0.00 110.0
 0.00 100.0
 0.00  90.0
 0.00  80.0
 0.00  70.0
 0.00  60.0
 0.00  50.0
 0.00  40.0
 0.00  30.0
 0.00  20.0
 0.00  10.0
 0.00   0.0

 0.25 360.0
 0.25 350.0
 0.25 340.0
 0.25 330.0
 0.25 320.0
 0.25 310.0
 0.25 300.0
 0.25 290.0
 0.25 280.0
 0.25 270.0
 0.25 260.0
 0.25 250.0
 0.25 240.0
 0.25 230.0
 0.25 220.0
 0.25 210.0
 0.25 200.0
 0.25 190.0
 0.25 180.0
 0.25 170.0
 0.25 160.0
 0.25 150.0
 0.25 140.0
 0.25 130.0
 0.25 120.0
 0.25 110.0
 0.25 100.0
 0.25  90.0
 0.25  80.0
 0.25  70.0
 0.25  60.0
 0.25  50.0
 0.25  40.0
 0.25  30.0
 0.25  20.0
 0.25  10.0
 0.25   0.0

 0.50 360.0
 0.50 350.0
 0.50 340.0
 0.50 330.0
 0.50 320.0
 0.50 310.0
 0.50 300.0
 0.50 290.0
 0.50 280.0
 0.50 270.0
 0.50 260.0
 0.50 250.0
 0.50 240.0
 0.50 230.0
 0.50 220.0
 0.50 210.0
 0.50 200.0
 0.50 190.0
 0.50 180.0
 0.50 170.0
 0.50 160.0
 0.50 150.0
 0.50 140.0
 0.50 130.0
 0.50 120.0
 0.50 110.0
 0.50 100.0
 0.50  90.0
 0.50  80.0
 0.50  70.0
 0.50  60.0
 0.50  50.0
 0.50  40.0
 0.50  30.0
 0.50  20.0
 0.50  10.0
 0.50   0.0

 0.75 360.0
 0.75 350.0
 0.75 340.0
 0.75 330.0
 0.75 320.0
 0.75 310.0
 0.75 300.0
 0.75 290.0
 0.75 280.0
 0.75 270.0
 0.75 260.0
 0.75 250.0
 0.75 240.0
 0.75 230.0
 0.75 220.0
 0.75 210.0
 0.75 200.0
 0.75 190.0
 0.75 180.0
 0.75 170.0
 0.75 160.0
 0.75 150.0
 0.75 140.0
 0.75 130.0
 0.75 120.0
 0.75 110.0
 0.75 100.0
 0.75  90.0
 0.75  80.0
 0.75  70.0
 0.75  60.0
 0.75  50.0
 0.75  40.0
 0.75  30.0
 0.75  20.0
 0.75  10.0
 0.75   0.0

 1.00 360.0
 1.00 350.0
 1.00 340.0
 1.00 330.0
 1.00 320.0
 1.00 310.0
 1.00 300.0
 1.00 290.0
 1.00 280.0
 1.00 270.0
 1.00 260.0
 1.00 250.0
 1.00 240.0
 1.00 230.0
 1.00 220.0
 1.00 210.0
 1.00 200.0
 1.00 190.0
 1.00 180.0
 1.00 170.0
 1.00 160.0
 1.00 150.0
 1.00 140.0
 1.00 130.0
 1.00 120.0
 1.00 110.0
 1.00 100.0
 1.00  90.0
 1.00  80.0
 1.00  70.0
 1.00  60.0
 1.00  50.0
 1.00  40.0
 1.00  30.0
 1.00  20.0
 1.00  10.0
 1.00   0.0

功能表

  0   2  76  74   1  39  75  37  38
  2   4  78  76   3  41  77  39  40
  4   6  80  78   5  43  79  41  42
  6   8  82  80   7  45  81  43  44
  8  10  84  82   9  47  83  45  46
 10  12  86  84  11  49  85  47  48
 12  14  88  86  13  51  87  49  50
 14  16  90  88  15  53  89  51  52
 16  18  92  90  17  55  91  53  54
 18  20  94  92  19  57  93  55  56
 20  22  96  94  21  59  95  57  58
 22  24  98  96  23  61  96  59  60
 24  26 100  98  25  63  99  61  62
 26  28 102 100  27  65 101  63  64
 28  30 104 102  29  67 103  65  66
 30  32 106 104  31  69 105  67  68
 32  34 108 106  33  71 107  69  70
 34  36 110 108  35  73 109  71  72

 74  76 150 148  75 113 149 111 112
 76  78 152 150  77 115 151 113 114
 78  80 154 152  79 117 153 115 116
 80  82 156 154  81 119 155 117 118
 82  84 158 156  83 121 157 119 120
 84  86 160 158  85 123 159 121 122
 86  88 162 160  87 125 161 123 124
 88  90 164 162  89 127 163 125 126
 90  92 166 164  91 129 165 127 128
 92  94 168 166  93 131 167 129 130
 94  96 170 168  95 133 169 131 132
 96  98 172 170  97 135 171 133 134
 98 100 174 172  99 137 173 135 136
100 102 176 174 101 139 175 137 138
102 104 178 176 103 141 177 139 140
104 106 180 178 105 143 179 141 142
106 108 182 180 107 145 181 143 144
108 110 184 182 109 147 183 145 146

148 150 224 222 149 187 223 185 186
150 152 226 224 151 189 225 187 188
152 154 228 226 153 191 227 189 190
154 156 230 228 155 193 229 191 192
156 158 232 230 157 195 231 193 194
158 160 234 232 159 197 233 195 196
160 162 236 234 161 199 235 197 198
162 164 238 236 163 201 237 199 200
164 166 240 238 165 203 239 201 202
166 168 242 240 167 205 241 203 204
168 170 244 242 169 207 243 205 206
170 172 246 244 171 209 245 207 208
172 174 248 246 173 211 247 209 210
174 176 250 248 175 213 249 211 212
176 178 252 250 177 215 251 213 214
178 180 254 252 179 217 253 215 216
180 182 256 254 181 219 255 217 218
182 184 258 256 183 221 257 219 220

222 224 298 296 223 261 297 259 260
224 226 300 298 225 263 299 261 262
226 228 302 300 227 265 301 263 264
228 230 304 302 229 267 303 265 266
230 232 306 304 231 269 305 267 268
232 234 308 306 233 271 307 269 270
234 236 310 308 235 273 309 271 272
236 238 312 310 237 275 311 273 274
238 240 314 312 239 277 313 275 276
240 242 316 314 241 279 315 277 278
242 244 318 316 243 281 317 279 280
244 246 320 318 245 283 319 281 282
246 248 322 320 247 285 321 283 284
248 250 324 322 249 287 323 285 286
250 252 326 324 251 289 325 287 288
252 254 328 326 253 291 327 289 290
254 256 330 328 255 293 329 291 292
256 258 332 330 257 295 331 293 294

在此处输入图片描述

(可以通过删除一些重复的点(如顶点或角度 360 和 0)来稍微优化这一点)。

相关内容