From octave-sources-request at bevo dot che dot wisc dot edu Wed Nov 28 00:54:31 2001 Subject: Re: Some simple plot stuff (saving plots as .eps, .png and .gif) From: Jakub Stastny To: octave-sources at bevo dot che dot wisc dot edu CC: octave-sources at bevo dot che dot wisc dot edu Date: Wed, 28 Nov 2001 07:54:13 +0100 This is a multi-part message in MIME format. --------------040108020101070408010703 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Hello! I use similar scripts for a long time; but not so elegant. I tried to write them to be "matlab-compatible". At first I made a small function isoctave which returns 1 if it runs in Octave and 0 in Matlab. This test is made in a really stupid way - it only checks the numbers returned by version command and if major is two, then it is Octave. But it works ;-) I have to preserve the compatibility of scripts amongst Matlab and Octave to the maximum possible extent (at home I use Octave, in school Matlab). Then, I have the following fork in the printing script: if (isoctave==1) %Octave printing stuff eval('gset terminal fig color big'); eval(sprintf('gset output ''%s.fig''',fname)); eval('replot'); % The conversion is possible, but sometimes the fig is not exported enough % fast - the export is made by an independent process! % system(sprintf('fig2dev -Lpng -m2 %s.fig %s.png',fname,fname)); eval('gset terminal X11'); eval('replot'); %Matlab doesn't know what replot is - that's why there is eval as well else %Matlab printing stuff eval(sprintf('print -dpng %s.png',fname)); end; I do the printing via fig - it is really nice, due to the possibility of editing in xfig. And it is possible to convert figs to any other formats by fig2dev. have a nice day Jakub BTW: what about Octave port for Windows? Last week I have downloaded the self-executable package (installation without compilation) - sized about 7MBs (I am not quite sure about this figure), after unpacking the directory was only about 3.8Megs big (and it didn't work, of course). But the installation program ended correctly - without any complains. I repeated downloading and unpacking for three times, because I thought it is due to archive corruption during downloading - but the result was the same in all the cases (and it didn't work, of course). I tried all the packages, which were referenced on WWW pages; none of them worked on my computer. Did anybody of you experience such a problem, or it is only a local behaviour of my computer? Or, most probably, I have left out somthing on WWW pages like "install this as well"? It is not a problem of me, because I have my Linux - Windows are not for me. But my friend wanted to play with it - and he has only Wins. William Hunter wrote: >Small script files that saves your current plot as either .eps, .png or .gif >format. Especially useful when plots has to be included in a PostScript >document (or other fomat for .png and .gif). > > >------------------------------------------------------------------------ > >## Copyright (C) 2000 William Hunter >## >## This file is part of Octave. >## >## Octave is free software; you can redistribute it and/or modify it >## under the terms of the GNU General Public License as published by >## the Free Software Foundation; either version 2, or (at your option) >## any later version. >## >## Octave is distributed in the hope that it will be useful, but >## WITHOUT ANY WARRANTY; without even the implied warranty of >## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >## General Public License for more details. >## >## You should have received a copy of the GNU General Public License >## along with Octave; see the file COPYING. If not, write to the Free >## Software Foundation, 59 Temple Place - Suite 330, Boston, MA >## 02111-1307, USA. > >## plt2gif: >## Converts the current plot to GIF format (.gif) >## by envoking GNUPLOT commands from OCTAVE. The GNUPLOT terminal is >## reset to the default (X11) after execution of the script. >## >## Usage: plt2gif("filename") >## >## Example: >## USER input: plt2gif("papaya") >## OCTAVE output: papaya.gif (saved in your working directory) > >## Author: W. Hunter >## Created: 25 November 2001 > >function plt2gif (filename) > > gset terminal gif small size 640,480 xffffff x000000 x404040 xff0000 xffa500 x66cdaa; > eval(sprintf("gset output \"%s%s\" \n",filename,".gif")); > replot; > gset terminal X11; > printf("\nWrote %s/%s%s \n \n",pwd,filename,".gif"); > >endfunction > > > >------------------------------------------------------------------------ > >## Copyright (C) 2000 William Hunter >## >## This file is part of Octave. >## >## Octave is free software; you can redistribute it and/or modify it >## under the terms of the GNU General Public License as published by >## the Free Software Foundation; either version 2, or (at your option) >## any later version. >## >## Octave is distributed in the hope that it will be useful, but >## WITHOUT ANY WARRANTY; without even the implied warranty of >## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >## General Public License for more details. >## >## You should have received a copy of the GNU General Public License >## along with Octave; see the file COPYING. If not, write to the Free >## Software Foundation, 59 Temple Place - Suite 330, Boston, MA >## 02111-1307, USA. > >## plt2png: >## Converts the current plot to Portable Network Graphics format (.png) >## by envoking GNUPLOT commands from OCTAVE. The GNUPLOT terminal is >## reset to the default (X11) after execution of the script. >## >## Usage: plt2png("filename") >## >## Example: >## USER input: plt2png("papaya") >## OCTAVE output: papaya.png (saved in your working directory) > >## Author: W. Hunter >## Created: 25 November 2001 > >function plt2png (filename) > > gset terminal png small color; > eval(sprintf("gset output \"%s%s\" \n",filename,".png")); > replot; > gset terminal X11; > printf("\nWrote %s/%s%s \n \n",pwd,filename,".png"); > >endfunction > > > >------------------------------------------------------------------------ > >## Copyright (C) 2000 William Hunter >## >## This file is part of Octave. >## >## Octave is free software; you can redistribute it and/or modify it >## under the terms of the GNU General Public License as published by >## the Free Software Foundation; either version 2, or (at your option) >## any later version. >## >## Octave is distributed in the hope that it will be useful, but >## WITHOUT ANY WARRANTY; without even the implied warranty of >## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >## General Public License for more details. >## >## You should have received a copy of the GNU General Public License >## along with Octave; see the file COPYING. If not, write to the Free >## Software Foundation, 59 Temple Place - Suite 330, Boston, MA >## 02111-1307, USA. > >## plt2eps: >## Converts the current plot to Encapsulated Postscript format (.eps) >## by envoking GNUPLOT commands from OCTAVE. The GNUPLOT terminal is >## reset to the default (X11) after execution of the script. >## >## Usage: plt2eps("filename") >## >## Example: >## USER input: plt2eps("papaya") >## OCTAVE output: papaya.eps (saved in your working directory) > >## Author: W. Hunter & K. M. Goosen >## Created: 13 September 2000 > >function plt2eps (filename) > > gset terminal postscript eps enhanced color; > eval(sprintf("gset output \"%s%s\" \n",filename,".eps")); > replot; > gset terminal X11; > printf("\nWrote %s/%s%s \n \n",pwd,filename,".eps"); > >endfunction > -- ------------------------------------------------------------------ Jakub Stastny Radost z chapani a uvazovani student je nejkrasnejsim darem matky Prirody. [Albert Einstein] ------------------------------------------------------------------ --------------040108020101070408010703 Content-Type: text/plain; name="isoctave.m" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="isoctave.m" function [isitoctave]=isoctave() ver = version; ver_n = str2num(ver(1:3)); if ver_n == 2 isitoctave = 1; else isitoctave = 0; end; --------------040108020101070408010703--