|
From: Junghun S. <nut...@li...> - 2012-01-19 11:47:00
|
Hi, everyone.
I want to control the size of canvas as well as that of figure. I found a solution for 2d plot and could adapt it to fit my need. But the same script does not work when I changed 'plot' command to 'splot' with pm3d. What am I missing?
I put the scripts at the bottom and eps files generated. First one is for 2d and is working well. The other is for 3d and is not working as I expected.
The difference between them is just:
+set pm3d map
-plot sin(x) ls 1
+splot sin(x) with pm3d
To run the script, perl is necessary. I'm using it to calculate the ratio, dimension of canvas and figure.
I'm using perl v5.12.3 built for MSWin32-x86-multi-thread (Strawberry Perl).
I'm running Matsuoka's MinGW build 4.5 patchlevel 0 in Windows 7 SP1, x64.
[1st script: fixedCanvasSize.TemplateFor2DPlot.plt.pl]
#!/usr/bin/env perl
#2d plot with fixed canvas size
# Embedding gnuplot script inside perl script.
# Below is the verbatim comment by the original author.
# -------------------------------------------------------
# Generate postscript and png plot with GNUplot from Perl
# Author: Ioan Vancea
# Usage: Give "data file" as an argument for script
# -------------------------------------------------------
# Note: no argument necessary. (Jan 19, 2012)
use strict;
use warnings;
my $XDim=170;
my $YDim=160;
my $CanvasRatio = $YDim/$XDim;
my $FigPaddingInch = 0.1;
#Size of canvas and figure is determined with the width of canvas, canvas ratio and padding.
my $FigCanvasXInch = 1.2;
my $FigCanvasYInch = sprintf("%.2f", $FigCanvasXInch * $CanvasRatio);
my $FigXInch = $FigCanvasXInch + 2 * $FigPaddingInch;
my $FigYInch = $FigCanvasYInch + 2 * $FigPaddingInch;
my $FigLineWidth = 0.8;
my $FigLineWidthInch = 0.8/72; #linewidth is in pt. Divide it by 72 to convert it to inch.
my $FigLinestyleWidth = 1.5;
#my $file = $ARGV[0]; #I simply didn't use it.
my $OutFn="fixedCanvasSize.TemplateFor2DPlot";
print "ratio: $CanvasRatio\n";
print "FigLineWidth: $FigLineWidth\n";
print "Canvas size: ($FigCanvasXInch, $FigCanvasYInch)\n";
print "Fig size: ($FigXInch, $FigYInch)\n";
# POSTSCRIPT
open (GNUPLOT, "|gnuplot");
print GNUPLOT <<EOF_PLOT;
#Using multiplot to fix the canvas size.
#Suggested by THeo in
#http://objectmix.com/graphics/139180-fixed-graph-box-size.html
reset
set size ratio $CanvasRatio
set origin 0,0
set term postscript eps enhanced \\
"Helvetica, 8" \\
color nobackground \\
dashlength 1.0 linewidth $FigLineWidth \\
butt size $FigXInch, $FigYInch
#LineSetting
set linestyle 1 lc rgb "#cc0000" lw $FigLinestyleWidth lt 1 #Scarlet Red 2
set linestyle 2 lc rgb "#73d216" lw $FigLinestyleWidth lt 2 #Chameleon 2
set linestyle 3 lc rgb "#3465a4" lw $FigLinestyleWidth lt 3 #Sky Blue 2
set linestyle 4 lc rgb "#75507b" lw $FigLinestyleWidth lt 4 #Plum 2
set linestyle 5 lc rgb "#729fcf" lw $FigLinestyleWidth lt 5 #Sky Blue 1 (light)
set linestyle 6 lc rgb "#edd400" lw $FigLinestyleWidth lt 6 #Butter 2
set linestyle 7 lc rgb "#f57900" lw $FigLinestyleWidth lt 7 #Orange 2
set linestyle 8 lc rgb "#d3d7cf" lw $FigLinestyleWidth lt 1 #Aluminium 2
#GridLineSetting
set linestyle 9 lc rgb "#d3d7cf" lw 0.5 lt 2 #Aluminium 2
set grid ls 9 back
set linestyle 10 lc rgb "#000000" lw 2*$FigLineWidth lt 1 #Aluminium 2
set output "$OutFn.eps"
set multiplot
set size $FigCanvasXInch/$FigXInch, $FigCanvasYInch/$FigYInch
OriginX = 2*$FigPaddingInch-$FigLineWidthInch
OriginY = OriginX
set origin OriginX/$FigXInch, OriginY/$FigYInch
set lmargin 0
set rmargin 0
set tmargin 0
set bmargin 0
set xtics out right scale 0.5 #right-alignment to keep labels from overflowing.
set ytics out scale 0.5 #scale <%f> to shorten the length of tic bar.
#Custom color box
set colorbox vertical user origin graph 0.1, 0.1 size graph 0.05, 0.25 front border 10 #Position at bottom left of the figure, size is small.
set cbtics out 1 nomirror scale 0.5
plot sin(x) ls 1
unset multiplot
EOF_PLOT
close(GNUPLOT);
#~ my $ret = `epstopdf $OutFn.eps`;
#~ my $ret = `convert -density 600x600 $OutFn.eps -compress LZW $OutFn.tif`;
#~ print "Convert returned $ret.\n";
[END of 1st script]
[2nd script: fixedCanvasSize.TemplateForPM3DPlot.plt.pl]
#!/usr/bin/env perl
#pm3d plot with fixed canvas size
# Embedding gnuplot script inside perl script.
# Below is the verbatim comment by the original author.
# -------------------------------------------------------
# Generate postscript and png plot with GNUplot from Perl
# Author: Ioan Vancea
# Usage: Give "data file" as an argument for script
# -------------------------------------------------------
# Note: no argument necessary. (Jan 19, 2012)
use strict;
use warnings;
my $XDim=170;
my $YDim=160;
my $CanvasRatio = $YDim/$XDim;
my $FigPaddingInch = 0.1;
#Size of canvas and figure is determined with the width of canvas, canvas ratio and padding.
my $FigCanvasXInch = 1.2;
my $FigCanvasYInch = sprintf("%.2f", $FigCanvasXInch * $CanvasRatio);
my $FigXInch = $FigCanvasXInch + 2 * $FigPaddingInch;
my $FigYInch = $FigCanvasYInch + 2 * $FigPaddingInch;
my $FigLineWidth = 0.8;
my $FigLineWidthInch = 0.8/72; #linewidth is in pt. Divide it by 72 to convert it to inch.
my $FigLinestyleWidth = 1.5;
#my $file = $ARGV[0]; #I simply didn't use it.
my $OutFn="fixedCanvasSize.TemplateForPM3DPlot";
print "ratio: $CanvasRatio\n";
print "FigLineWidth: $FigLineWidth\n";
print "Canvas size: ($FigCanvasXInch, $FigCanvasYInch)\n";
print "Fig size: ($FigXInch, $FigYInch)\n";
# POSTSCRIPT
open (GNUPLOT, "|gnuplot");
print GNUPLOT <<EOF_PLOT;
#Using multiplot to fix the canvas size.
#Suggested by THeo in
#http://objectmix.com/graphics/139180-fixed-graph-box-size.html
reset
set size ratio $CanvasRatio
set origin 0,0
set term postscript eps enhanced \\
"Helvetica, 8" \\
color nobackground \\
dashlength 1.0 linewidth $FigLineWidth \\
butt size $FigXInch, $FigYInch
#LineSetting
set linestyle 1 lc rgb "#cc0000" lw $FigLinestyleWidth lt 1 #Scarlet Red 2
set linestyle 2 lc rgb "#73d216" lw $FigLinestyleWidth lt 2 #Chameleon 2
set linestyle 3 lc rgb "#3465a4" lw $FigLinestyleWidth lt 3 #Sky Blue 2
set linestyle 4 lc rgb "#75507b" lw $FigLinestyleWidth lt 4 #Plum 2
set linestyle 5 lc rgb "#729fcf" lw $FigLinestyleWidth lt 5 #Sky Blue 1 (light)
set linestyle 6 lc rgb "#edd400" lw $FigLinestyleWidth lt 6 #Butter 2
set linestyle 7 lc rgb "#f57900" lw $FigLinestyleWidth lt 7 #Orange 2
set linestyle 8 lc rgb "#d3d7cf" lw $FigLinestyleWidth lt 1 #Aluminium 2
#GridLineSetting
set linestyle 9 lc rgb "#d3d7cf" lw 0.5 lt 2 #Aluminium 2
set grid ls 9 back
set linestyle 10 lc rgb "#000000" lw 2*$FigLineWidth lt 1 #Aluminium 2
set output "$OutFn.eps"
set multiplot
set pm3d map
set size $FigCanvasXInch/$FigXInch, $FigCanvasYInch/$FigYInch
OriginX = 2*$FigPaddingInch-$FigLineWidthInch
OriginY = OriginX
set origin OriginX/$FigXInch, OriginY/$FigYInch
set lmargin 0
set rmargin 0
set tmargin 0
set bmargin 0
set xtics out right scale 0.5 #right-alignment to keep labels from overflowing.
set ytics out scale 0.5 #scale <%f> to shorten the length of tic bar.
#Custom color box
set colorbox vertical user origin graph 0.1, 0.1 size graph 0.05, 0.25 front border 10 #Position at bottom left of the figure, size is small.
set cbtics out 1 nomirror scale 0.5
splot sin(x) with pm3d
unset multiplot
EOF_PLOT
close(GNUPLOT);
#~ my $ret = `epstopdf $OutFn.eps`;
#~ my $ret = `convert -density 600x600 $OutFn.eps -compress LZW $OutFn.tif`;
#~ print "Convert returned $ret.\n";
[END of 2nd script]
Thanks in advance for any info.
Best,
Junghun Shin
[Please find figures here]
Fixing canvas size for 3d plots with pm3d.
https://skydrive.live.com/redir.aspx?cid=71d1ea4884739940&page=browse&resid=71D1EA4884739940!408&sc=Documents&authkey=!AN2PwaY3pfE0Adg&Bpub=SDX.SkyDrive&Bsrc=SkyMail
https://skydrive.live.com/redir.aspx?cid=71d1ea4884739940&page=browse&resid=71D1EA4884739940!408&sc=Documents&authkey=!AN2PwaY3pfE0Adg&Bpub=SDX.SkyDrive&Bsrc=SkyMail
|