image - 使用 gnuplot pm3d 和 pdf 输出生成的图像中有问题的莫尔图案

我正在使用此处讨论的命令文件绘制数据: gnuplot contour line color: set style line and set linetype not working 我想提供不同的输出选项。 PNG 和 wxt 终端一样运行良好,但是,它们具有固定的分辨率,例如当我“放大”绘图时,它变得更加颗粒化。

如果我将 pdf 或 pdfcairo 用于终端,则生成的文件具有波纹图案。通过在 pm3d 命令中增加插值量,可以减少图像中观察到波纹图案的区域。径向方向的数据集中有很多点,但角度数据集不多,所以我需要在那个“方向”上插值更多。不使用插值会产生非常颗粒状的 pm3d 图像,因此我一直在尝试 0,20 到 20,20 甚至 20,40。不幸的是,即使很多插值也不能完全消除莫尔图案,使文件大小变得巨大(例如,PNG 文件约为 250kB,但 pdf 文件超过 11MB),因此渲染速度非常慢。我尝试使用 Adob​​e Acrobat Reader 10.1.8 和 GSview 查看这些,结果是一样的。

我对使用 pdf 格式很感兴趣,因为它无处不在并且可以放大而不会过度丢失细节(与 PNG 不同)。

下面是我在不同级别的插值下捕获的结果 pdf 输出中的模式的几个屏幕截图。第一张图片是供引用的 png 文件,因为它没有显示波纹图案,文件大小为 250kB。

接下来是没有pm3d插值的pdf输出,72kB文件大小:

接下来,pdf输出使用set pm3d map interpolate 0,20,文件大小1861kB:

接下来使用set pm3d map interpolate 10,20输出pdf,文件大小5942kB:

最后,使用set pm3d map interpolate 20,20输出pdf,文件大小11515kB:

为什么会为 pdf 输出生成这些波纹图案?有没有什么办法可以让我仍然拥有一种可以放大而不会(大量)降低分辨率的矢量格式?

最佳答案

这不应该是一个解决方案,而是一个解释和一个可能的解决方法,虽然丑陋。

gnuplot 邮件列表中不时会收到有关此问题的报告,但似乎与查看者有关。它与 gnuplot 创建曲面图的方式有关。这些被绘制为多边形,它们被缝合在一起。您显示的莫尔图案来自两个多边形之间的错误渲染。这取决于查看器、查看器设置和缩放系数。

显示该效果的最简单示例是以下 Postscript 文件:

%!PS-Adobe-2.0
50 50 moveto 50 0 rlineto 0 50 rlineto -50 0 rlineto closepath 0 setgray fill
100 50 moveto 50 0 rlineto 0 50 rlineto -50 0 rlineto closepath 0 setgray fill

保存此文件,例如为 moire.ps 并查看,或者用 ps2pdf 转换并查看。使用 Acrobat Reader 9.5.1,我看到以下内容:

Acrobat Reader 有一个设置Preferences -> Page Display -> Enhance thin lines 可以防止这个问题,但会导致其他部分出现问题。

在我的系统 (Debian) 上,所有查看器都显示此模式,mupdffirefoxghostscriptpdftocairo、libpoppler` 等

那么,怎么办?对于我自己,我使用以下解决方法。我 splot 为高分辨率的 png,稍后使用 plot ... with rgbimage 重新读取该文件。然后你得到你的热图作为位图,其余的是矢量的。在大多数情况下,这没有问题,因为无论如何,您都有一些分辨率有限的测量数据,您可以对这些数据进行插值。

基于问题gnuplot contour line color: set style line and set linetype not working , 以下是您可以如何实现它:

reset 

set lmargin at screen 0.05
set rmargin at screen 0.85
set bmargin at screen 0.1
set tmargin at screen 0.9

set pm3d map interpolate 20,20
unset key

set cntrparam bspline
set cntrparam points 10
set cntrparam levels increment -6,-6,-24
set contour surface

set linetype 1 lc rgb "blue" lw 2 
set linetype 2 lc rgb "blue"
set linetype 3 lc rgb "black"
set linetype 4 lc rgb "orange"
set linetype 5 lc rgb "yellow"

set palette rgb 33,13,10 #rainbow (blue-green-yellow-red)
set cbrange [-18:0]

unset border
unset xtics
unset ytics

set angles degree
r = 3.31
set xrange[-r:r]
set yrange[-r:r]
set colorbox user origin 0.9,0.1 size 0.03,0.8

##################### start changes ##############
set autoscale fix
RES_X = 2000
RES_Y = 2000

save('settings.tmp')
set lmargin at screen 0
set rmargin at screen 1
set bmargin at screen 0
set tmargin at screen 1
unset colorbox

set terminal pngcairo size RES_X, RES_Y
set output '3d-polar-inc.png'
splot 'new_test.dat' nocontour

unset output
load('settings.tmp')

# mapping of the coordinates for the png plotting later
X0 = GPVAL_X_MIN
Y0 = GPVAL_Y_MIN
DX = (GPVAL_X_MAX - GPVAL_X_MIN)/real(RES_X)
DY = (GPVAL_Y_MAX - GPVAL_Y_MIN)/real(RES_Y)
C0 = GPVAL_CB_MIN
DC = GPVAL_CB_MAX - GPVAL_CB_MIN
C(x) = (x/255.0) * DC + C0

# now plot the png 
#set terminal pdfcairo size 10cm,10cm
#set output '3d-polar.pdf'
set terminal postscript eps color level3 size 10cm,10cm solid
set output '3d-polar-eps.eps'

set multiplot

set cbrange[GPVAL_CB_MIN:GPVAL_CB_MAX]
plot '3d-polar-inc.png' binary filetype=png \
     origin=(X0, Y0) dx=DX dy=DY \
     using (C($1)):(C($2)):(C($3)) \
     with rgbimage, \
     NaN with image t '' # hack for getting the colorbox

# plot the contours
unset surface
unset pm3d
splot 'new_test.dat' w l

###################### end changes #################

# now plot the polar grid only
set style line 11 lc rgb 'black' lw 2 lt 0
set grid polar ls 11
set polar
set logscale r 10
set rrange[10:20000]
unset raxis
set rtics format '' scale 0
#set rtics axis scale 
set rtics (20,50,100,200,500,1000,2000,5000,10000,20000)
do for [i=-150:180:30] {
dum = r+0.15+0.05*int(abs(i/100))+0.05*int(abs(i/140))-0.05/abs(i+1)
set label i/30+6 at first dum*cos(i), first dum*sin(i) center sprintf('%d', i)
}
set label 20 at first 0, first -(log(20)/log(10)-1) center "20"
set label 100 at first 0, first -(log(100)/log(10)-1) center "100"
set label 200 at first 0, first -(log(200)/log(10)-1) center "200"
set label 1000 at first 0, first -(log(1000)/log(10)-1) center "1k"
set label 2000 at first 0, first -(log(2000)/log(10)-1) center "2k"
set label 10000 at first 0, first -(log(10000)/log(10)-1) center "10k"
set label 20000 at first 0, first -(log(20000)/log(10)-1) center "20k"
plot NaN w l
unset multiplot
unset output

使用 pdfcairo 这会得到一个 1.7 MB 的 pdf 文件,使用 epslatex level3 (此选项仅在 4.7 开发版本中可用)你会得到一个 1.5 MB 的 eps 文件,可以使用 epstopdf 将其转换为 136 KB 的 pdf 文件。

另请参阅我对 Big data surface plots: Call gnuplot from tikz to generate bitmap and include automatically? 的回答在 TeX.SX 上。

https://stackoverflow.com/questions/18927493/

相关文章:

.htaccess - 我如何使用 htaccess 在测试 wamp 服务器上重定向

JavaFX - 使用 CSS 为文本字段设置焦点边框

c# - ComboBox 向上/向下箭头键在项目重新填充后发出

animation - SVG 元素上的多个动画

regex - 如何将 1100 行中的每 5 行合并为 1 行

integer - 有符号和无符号整数?

scala - 运行 future n 次

php - 为什么 PHP-FPM 需要 5 分钟才能在我的服务器上重新启动?

python - 将 matplotlib 图导出到 HTML 文件

emacs - 如何使用预定义窗口启动 Emacs?