使用gnuplot pm3d和pdf输出生成的图像中有问题的莫尔图案 [英] problematic Moire pattern in image produced with gnuplot pm3d and pdf output

查看:401
本文介绍了使用gnuplot pm3d和pdf输出生成的图像中有问题的莫尔图案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此处讨论的命令文件绘制数据:
,以下是如何实现它:

 重置

在屏幕上设置lmargin 0.05
在屏幕上设置rmargin 0.85
在屏幕设置bmargin 0.1
在屏幕上设置tmargin 0.9

set pm3d map interpolate 20,20
unset key

set cntrparam bspline
set cntrparam points 10
set cntrparam级别增量-6,-6,-24
设置轮廓曲面

设置线型1 lc rgb蓝色lw 2
设置线型2 lc rgbblue
set linetype 3 lc rgbblack
set linetype 4 lc rgborange
set linetype 5 lc rgbyellow

set palette rgb 33,13,10 #rainbow(蓝绿黄 - 红)
设置cbrange [-18:0]

未设置边框
unset xtics
unset ytics

set angle degree
r = 3.31
set xrange [-r:r]
set yrange [-r: r]
设置colorbox用户来源0.9,0.1大小0.03,0.8

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

save('settings.tmp')
在屏幕0设置lmargin
在屏幕1设置rmargin
在屏幕0设置bmargin
在屏幕1设置tmargin
未设置colorbox

设置终端pngcairo大小RES_X,RES_Y
设置输出'3d-polar-inc.png'
splot'new_test.dat'nocontour

unset output
load('settings .tmp')

#映射后面的png坐标的映射
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

#现在绘制png
#set终点al pdfcairo尺寸10cm,10cm
#set输出'3d-polar.pdf'
设置终端postscript eps颜色level3尺寸10cm,10cm实心
设置输出'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 \
使用(C($ 1)):( C($ 2)):( C($ 3))\
with rgbimage,\
NaN with image t''#hack for get colorbox

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

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

#现在只绘制极地网格
设置样式行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)
为[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) )
设置标签i / 30 + 6在第一个dum * cos(i),第一个dum * sin(i)中心sprintf('%d',i)
}
设置标签20在第一个0,第一个 - (log(20)/ log(10)-1)中心20
设置标签100在第一个0,第一个 - (log(100)/ log(10)-1)中心100
设置标签200在第一个0,第一个 - (log(200)/ log(10)-1)中心200
设置标签1000在第一个0,第一个 - (log(1000) )/ log(10)-1)center1k
set label 2000 at first 0,first - (log(2000)/ log(10)-1)center2k
set label 10000在第一个0,第一个 - (log(10000)/ log(10)-1)中心10k
设置标签20000在第一个0,第一个 - (log(20000)/ log(10)-1)中心20k
plot NaN wl
unset multiplot
unset output

使用 pdfcairo ,这将提供1.7 MB的pdf文件, epslatex level3 (此选项在4.7开发版本中可用只有)你得到一个1.5 MB的eps文件,可以用<$ c $转换c> epstopdf 到136 KB的pdf文件。



另请参阅我对大数据表面图:从tikz调用gnuplot生成位图并自动包含?在TeX.SX上。


I'm plotting data using the command files discussed here: gnuplot contour line color: set style line and set linetype not working I want to provide different output options. PNG works well, as does the wxt terminal, however, these have fixed resolution, e.g. when I "zoom in" on the plot it gets grainier.

If I use pdf or pdfcairo for the terminal, the resulting file has a Moire pattern. The region in the image over which the Moire pattern is observed can be reduced by using increasing amounts of interpolation in the pm3d command. There are lots of points in the data set in the radial direction, but not many angular sets of data, so I need to interpolate more in that "direction". Using no interpolation results in a very grainy pm3d image, so I have been trying 0,20 to 20,20 or even 20,40. Unfortunately even lots of interpolation does not completely get rid of the Moire pattern, makes the file size HUGE (e.g. the PNG file is around 250kB but the pdf file is over 11MB) and as a result it renders very slowly. I've tried viewing these with Adobe Acrobat Reader 10.1.8 and GSview and the result is the same.

I am interested in using the pdf format because it is ubiquitous and can be zoomed in without excessive loss of detail (unlike PNG).

Below are a couple of screen shots that I captured of the pattern in the resulting pdf output at different levels of interpolation. The first image is the png file for reference as it shows no Moire pattern, 250kB file size.

Next, the pdf output without pm3d interpolation, 72kB file size:

Next, the pdf output using set pm3d map interpolate 0,20, file size 1861kB:

Next, the pdf output using set pm3d map interpolate 10,20, file size 5942kB:

Finally, the pdf output using set pm3d map interpolate 20,20, file size 11515kB:

Why are these Moire patterns generated for the pdf outputs? Is there away around this, that would allow me to still have a vector format that can be zoomed in without (much) loss of resolution?

解决方案

This is not supposed to be a solution, but rather an explanation and a possible, although ugly workaround.

From time to time there are reports to the gnuplot mailinglists about this issue, but it seems to be related to the viewers. It has to do with the way gnuplot creates the surfaces plots. These are drawn as polygons, which are stitched together. The Moiré patterns you are showing come from wrong rendering between two polygons. That depends on the viewer, the viewer settings and the zoom factor.

The easiest example, to show that effect is the following Postscript file:

%!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

Save this file e.g. as moire.ps and view it, or convert it with ps2pdf and view it. With the Acrobat reader 9.5.1 I see the following:

The Acrobat Reader has a setting Preferences -> Page Display -> Enhance thin lines which can prevent this problem, but causes problems on other parts.

On my system (Debian), all viewers show this patterns, mupdf, firefox, ghostscript, pdftocairo, libpoppler` etc.

So, what to do? For myself I use the following workaround. I splot to a png with high resolution, and reread that file later with plot ... with rgbimage. Then you get your heatmap as bitmap, and the rest is vectorial. In most cases this is no problem, because in any way you have some measurement data with limited resolution, which you interpolate.

Based on the question gnuplot contour line color: set style line and set linetype not working, here is how you can implement it:

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

With pdfcairo this gives a 1.7 MB pdf file, with epslatex level3 (this option is available in the 4.7 development version only) you get a 1.5 MB eps file, which can be converted with epstopdf to a 136 KB pdf file.

See also my answer to Big data surface plots: Call gnuplot from tikz to generate bitmap and include automatically? on TeX.SX.

这篇关于使用gnuplot pm3d和pdf输出生成的图像中有问题的莫尔图案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆