[Scilab-users] Smarter way to save plot graphics?

Claus Futtrup cfuttrup at gmail.com
Sun Oct 5 19:07:55 CEST 2014


Hi there

I've made a small script (see below), which saves some generated plots 
to either jpg, pdf, png or svg.

My question is whether there's a smarter way to do this with what Scilab 
offers today?

Ideally Scilab would support a function - lets call it "saveplt" - but 
as you may notice in the below code, each type of graphics export 
requires different parameters. If one could call saveplt and specify 
output file format, I could reduce the amount (lines) of code a lot. I'm 
just wondering if Scilab already today offers some smarter way to do it 
already?

Best regards,
Claus

Code:

// savegraphs.sce
// Saves the generated figures in graphics files.
// Existing files are overwritten!

// Choice of graphics format is specified in saveplots variable
// svg,png,  pdf  orjpg
// Any other string is ignored

dataname  =  datadir  +  '\'  +  name;

select  saveplots
case  "svg"  then
     xs2svg(326,  dataname  +  '_326',  'portrait');  // Export to SVG file,
     xs2svg(327,  dataname  +  '_327',  'portrait');  // portrait orientation.
     xs2svg(328,  dataname  +  '_328',  'portrait');
     xs2svg(329,  dataname  +  '_329',  'portrait');
     xs2svg(330,  dataname  +  '_330',  'portrait');
     xs2svg(331,  dataname  +  '_331',  'portrait');
     xs2svg(332,  dataname  +  '_332',  'portrait');
case  "png"  then
     xs2png(326,  dataname  +  '_326');  // Export to PNG file.
     xs2png(327,  dataname  +  '_327');
     xs2png(328,  dataname  +  '_328');
     xs2png(329,  dataname  +  '_329');
     xs2png(330,  dataname  +  '_330');
     xs2png(331,  dataname  +  '_331');
     xs2png(332,  dataname  +  '_332');
case  "pdf"  then
     xs2pdf(326,  dataname  +  '_326',  'portrait');  // Export to PDF file,
     xs2pdf(327,  dataname  +  '_327',  'portrait');  // portrait orientation.
     xs2pdf(328,  dataname  +  '_328',  'portrait');
     xs2pdf(329,  dataname  +  '_329',  'portrait');
     xs2pdf(330,  dataname  +  '_330',  'portrait');
     xs2pdf(331,  dataname  +  '_331',  'portrait');
     xs2pdf(332,  dataname  +  '_332',  'portrait');
case  "jpg"  then
     xs2jpg(326,  dataname  +  '_326',  );  // Export to JPG file,
     xs2jpg(327,  dataname  +  '_327',  1);  // compression 1 (best quality).
     xs2jpg(328,  dataname  +  '_328',  1);
     xs2jpg(329,  dataname  +  '_329',  1);
     xs2jpg(330,  dataname  +  '_330',  1);
     xs2jpg(331,  dataname  +  '_331',  1);
     xs2jpg(332,  dataname  +  '_332',  1);
else  disp("Plots not saved");
end

// Files may be opened in for example LibreOffice DRAW


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20141005/4603feea/attachment.htm>


More information about the users mailing list