0

I am doing a heat transfer simulation into a cube and plotting the evolution through time with a 2D heatmap at mid-depth of the cube.

The issue is that the edges, while they represent the same value because it is a boundary condition, are not the same thickness on the heatmap during the simulation.

We can see that easier with the top and bottom boundaries, which are at 373 K, in red. Here is a screenshot of the .gif heatmap launched with "Image Viewer":

enter image description here

I join the dataset used to plot the heatmap:

  x      z       t      T
0.000  0.000  0.000  373.000
0.000  0.005  0.000  298.000
0.000  0.015  0.000  298.000
            ...
0.000  0.985  0.000  298.000
0.000  0.995  0.000  298.000
0.000  1.000  0.000  373.000

            ...
0.015  0.000  0.001  373.000
0.015  0.005  0.001  292.000
0.015  0.015  0.001  283.000
0.015  0.025  0.001  283.000
           ....
0.015  0.985  0.001  283.000
0.015  0.995  0.001  292.000
0.015  1.000  0.001  373.000

           ...

And here is the .plt code for Gnuplot:


set view map scale 1
set size square
set xlabel("x (m)")
set ylabel("z (m)")
set zlabel("T")
set xrange [-0.01:1.01]
set yrange [-0.01:1.01]
set title "Heat transfert 3D at mid depth of a cube"
set cblabel "T (K)"

set hidden3d
set palette rgb 33,13,10 
set cbrange [283:373] # colobar range

set pm3d implicit at s 
set pm3d corners2color max 

set term gif animate delay 100 

set output "para_heat_3D_insta_4_0.gif"

stats "plot_para_heat_3D_insta.dat"

do for [i=1:int(STATS_blocks)]{
    splot "plot_para_heat_3D_insta.dat" index (i-1) using 1:2:4 with pm3d notitle 

}

set output

Is someone has an idea and could help me? Thanks in advance.

Jejouze
  • 23
  • 6
  • I would guess this is a resolution or aliasing effect. From your example data (step size 0.005) I would assume that you have 201 x 201 values in x and z direction. What is your graph (active plot) size? I estimated something like 318 x 319 pixels. This will not fit well with your 201 x 201 values. If you resize your graph in such a way that the active plotting area would be 201 x 201 or 402 x 402 pixels, I would expect to see identical thick borders. – theozh Jan 12 '22 at 16:48
  • Thanks for your answer. Actually, I have 102 x 102 values in the x and z direction, because my size step is not constant. So, according to what you said, I should have an active plotting area of 102 x 102 or 204 x 204 pixels? I tried that " set terminal pngcairo size 204,204" , but there is still a difference. What I should add? – Jejouze Jan 13 '22 at 18:39
  • Setting the terminal size to 204,204 will set the whole graph (canvas) to 204 x 204 pixels. Hence the active plot area will be somewhat smaller, depending on the axis labels, titles etc. The fact that your data is not equidistant makes the situation even more complicated. For example, if you have step sizes of 0.50, 0.55 and 0.70 your smallest step would be 0.05 to avoid aliasing effects. Or in other words: each step should consist of an integer number of pixels (and not fractions of pixels). What are the different steps in your data? – theozh Jan 13 '22 at 19:19
  • There are only 2 different steps. The first one is 0.005 between the 1st and 2nd values and between the last and last - 1 values. The second one is between all others values and is equal to 0.01. It is the same for x and z. – Jejouze Jan 14 '22 at 12:32
  • @theozh When I use set size 1,1 , it is a bit better but not perfect... And I don't know how to deal with the 2 different steps and how to set the size in pixels of the active plot area. Could you help me? – Jejouze Jan 26 '22 at 11:16

1 Answers1

1

Unfortunately, I don't have a good solution. To my opinion it is an issue with the rendering library, which I cannot explain.

You can compare term pngcairo and term gif. It looks like the GIF-terminal always makes the thin lines in different thicknesses, whereas the PNG looks much better.

As a workaround for the GIF I tried to extract the "active plot area" in pixels of the gif image via the gnuplot variables GPVAL_... (in the gnuplot console type show var GPVAL). You get these values only after plotting. Therefore, I extract the margins from a first gif plot and set the new gif size accordingly and replot. Your step size of 0.005 should correspond to 2 pixels. However, this still doesn't give good results for the GIF. The new plot area should have a square size of 402+8 pixels pixels but it does not. I haven't yet found out why. Sorry, maybe somebody else has a better idea.

My recommendation for an alternative workaround, would be to generate all the frames as PNGs and then use another software to put them together to an animated GIF. For Windows I used ScreenToGif in the past.

Code:

### make the active plot a certain size in pixels
reset session

set view map scale 1
set size square

# create some test data
set print $Data
    M=10; N=200
    do for [x=0:M] for [y=0:N] {
        print sprintf("%g %g %g", real(x)/M, real(y)/N, !(y%N)*273)  # real() to avoid gnuplot's integer division
        if (y==N) { print ""}
    }
set print

set palette rgb 33,13,10
set pm3d corners2color max 
set xrange [-0.01:1.01]
set yrange [-0.01:1.01]
set key noautotitle

SizeX = 640
SizeY = 480
# 201 datapoints, with smallest stepsize 0.005
Factor = 2
DataSizeX = (201  + 4)*Factor   # +4 because of 4 "extra steps", i.e. range [-0.01:1.01]
DataSizeY = (201  + 4)*Factor 

# generate PNG
set term pngcairo size SizeX,SizeY font ",11"
set output "SO70684623.png"
splot $Data u 1:2:3 w pm3d

# generate preliminary GIF 
set term gif size SizeX,SizeY font ",11"
set output "SO70684623.gif"
replot

Tmargin(n)   = GPVAL_TERM_YSIZE-GPVAL_TERM_YMIN
Bmargin(n)   = GPVAL_TERM_YMAX
Rmargin(n)   = GPVAL_TERM_XSIZE-GPVAL_TERM_XMAX
Lmargin(n)   = GPVAL_TERM_XMIN
PlotAreaX(n) = GPVAL_TERM_XMAX-GPVAL_TERM_XMIN
PlotAreaY(n) = GPVAL_TERM_YMIN-GPVAL_TERM_YMAX
SizeXnew(n)  = DataSizeX + Lmargin(0) + Rmargin(0)
SizeYnew(n)  = DataSizeY + Tmargin(0) + Bmargin(0)
print sprintf("New size: %g,%g", SizeXnew(0),SizeYnew(0))

# generate final GIF
set term gif size SizeXnew(0),SizeYnew(0) font ",11"
set output "SO70684623_new.gif"
replot

print sprintf("New active area: %g,%g", PlotAreaX(0), PlotAreaY(0))
set output
### end of code

Result:

SO70684623.png (looks ok)

enter image description here

SO70684623.gif (unequal red lines on top and bottom)

enter image description here

SO70684623_new.gif (modified size, does not solve the issue)

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72