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

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

问题描述

我正在使用此处讨论的命令文件绘制数据:,这里是您可以的方法实施它:

重置将 lmargin 设置为屏幕 0.05将 rmargin 设置为屏幕 0.85在屏幕 0.1 设置 bmargin在屏幕 0.9 处设置 tmargin设置 pm3d 地图插值 20,20取消设置键设置cntrparam bspline设置 cntrparam 点 10设置 cntrparam 级别增量 -6,-6,-24设置轮廓曲面设置线型 1 lc rgb "blue" lw 2设置线型 2 lc rgb蓝色"设置线型 3 lc rgb黑色"设置线型 4 lc rgb橙色"设置线型 5 lc rgb黄色"设置调色板 rgb 33,13,10 #rainbow(蓝绿黄红)设置 cbrange [-18:0]未设置边框未设置 xtics未设置 ytics设置角度度r = 3.31设置 xrange[-r:r]设置 yrange[-r:r]设置 colorbox 用户原点 0.9,0.1 大小 0.03,0.8#################### 开始更改##############设置自动缩放修复RES_X = 2000RES_Y = 2000保存('settings.tmp')在屏幕 0 设置 lmargin在屏幕 1 设置 rmargin在屏幕 0 设置 bmargin在屏幕 1 设置 tmargin未设置颜色框设置终端 pngcairo 大小 RES_X, RES_Y设置输出 '3d-polar-inc.png'splot 'new_test.dat' nocontour未设置输出加载('settings.tmp')# 稍后绘制 png 坐标的映射X0 = GPVAL_X_MINY0 = GPVAL_Y_MINDX = (GPVAL_X_MAX - GPVAL_X_MIN)/真实(RES_X)DY = (GPVAL_Y_MAX - GPVAL_Y_MIN)/real(RES_Y)C0 = GPVAL_CB_MINDC = GPVAL_CB_MAX - GPVAL_CB_MINC(x) = (x/255.0) * DC + C0# 现在绘制 png#set 终端 pdfcairo 尺寸 10cm,10cm#设置输出'3d-polar.pdf'设置终端附言 eps 颜色 level3 大小 10cm,10cm 实心设置输出 '3d-polar-eps.eps'设置多图设置 cbrange[GPVAL_CB_MIN:GPVAL_CB_MAX]绘制3d-polar-inc.png"二进制文件类型=png 原点=(X0, Y0) dx=DX dy=DY 使用 (C($1)):(C($2)):(C($3)) 使用 rgbimage,NaN with image t '' # 获取颜色框的技巧# 绘制轮廓未设置表面取消设置pm3dsplot 'new_test.dat' w l##################### 结束更改################## 现在只绘制极坐标网格设置样式行 11 lc rgb 'black' lw 2 lt 0设置网格极坐标 ls 11设置极地设置 logscale r 10设置范围[10:20000]未设置轴设置 rtics 格式 '' 比例 0#set rtics 轴比例设置 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)在第一个 dum*cos(i) 处设置标签 i/30+6,第一个 dum*sin(i) 中心 sprintf('%d', i)}将标签 20 设置为第一个 0,第一个 -(log(20)/log(10)-1) 中心20"在第一个 0 处设置标签 100,第一个 -(log(100)/log(10)-1) 中心100"将标签 200 设置为第一个 0,第一个 -(log(200)/log(10)-1) 中心200"在第一个 0 处设置标签 1000,第一个 -(log(1000)/log(10)-1) 中心1k"将标签 2000 设置为第一个 0,第一个 -(log(2000)/log(10)-1) 中心2k"在第一个 0 处设置标签 10000,第一个 -(log(10000)/log(10)-1) 中心10k"将标签 20000 设置为第一个 0,第一个 -(log(20000)/log(10)-1) 中心20k"绘制 NaN w l取消设置多图未设置输出

使用 pdfcairo 这会得到一个 1.7 MB 的 pdf 文件,使用 epslatex level3(此选项仅在 4.7 开发版本中可用)你会得到一个 1.5 MB 的 eps 文件,可以使用 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天全站免登陆