4.47458

4.5 | 62 ratings Rate this file 240 downloads (last 30 days) File Size: 854.26 KB File ID: #7401

Scalable Vector Graphics (SVG) Export of Figures

by Juerg Schwizer

 

10 Apr 2005 (Updated 06 Mar 2010)

Code covered by the BSD License  

Converts 3D and 2D MATLAB plots to the scalable vector format (SVG).

Editor's Notes:

This file was a File Exchange Pick of the Week

Download Now | Watch this File

File Information
Description

Scalable Vector Graphics (SVG) Export of Figures

Converts 2D & 3D Matlab plots to the scalable vector format (SVG). This format is specified by W3C (http://www.w3.org) and can be viewed and printed with internet browsers.

Added preliminary support of filter, clipping, and tickmark extensions that go beyond the Matlab functionality. SVG filters are a great tool to create stylish plots! Try it out! Before you start using this new features have a look at the tutorial. More information and examples can be found on my webpage.
Tested browsers and editors for SVG filters:
  Opera 9.64,10.50 -> yes
  Firefox 3.5,3.6 -> yes
  Inkscape 0.46 -> yes (some limitations)
  IE + RENESIS -> no

Use plot2svg_depreciated if you face problems due to the additional features. The function plot2svg_depreciated was the plot2svg of the last release.

IMPORTANT: Use 'v6' graphics option for Matlab versions > R14! (see below)

Editors for the SVG file format can be found at http://www.inkscape.org.

Usage:
> plot2svg % opens a file dialog to plot the active figure
    or
> plot2svg('myfile.svg', figure handle, pixelfiletype)
    
  pixelfiletype = 'png' (default), 'jpg'

IMPORTANT: Firefox 1.5 may hang if too many linear shaded patches are used in the figure.

See http://www.juergschwizer.de to get more informations

Supported Features
- line, patch, contour, contourf, quiver, surf, ...
- markers
- image (saved as linked png pictures)
- grouping of elements
- alpha values for patches
- subplot
- colorbar
- legend
- zoom
- reverse axes
- controls are saved as png pictures
- log axis scaling
- axis scaling factors (10^x)
- labels that contain Latex commands are interpreted (with some limitations):
\alpha, \Alpha, \beta, \Beta, ... \infity, \pm, \approx
{\it.....} for italic text
{\bf.....} for bold text
^{...} for superscript
_{...} for subscript

How to use SVG files in HTML code
<object type="image/svg+xml" data="./mySVGfile.svg" width="140" height="100"></object>

Changes in Version 28-Jun-2009
- Improved depth sorting for patches and surface
- Bugfix patches
- Bugfix 3D axis handling

Changes in Version 11-Jul-2009
- Support of FontWeight and FontAngle properties
- Improved markers (polygon instead of polyline for closed markers)
- Added character encoding entry to be fully SVG 1.1 conform

Changes in Version 13-Jul-2009
- Support of rectangle for 2D
- Added preliminary support for SVG filters
- Added preliminary support for clipping with pathes
- Added preliminary support for turning axis tickmarks

Changes in Version 18-Jul-2009
- Line style scaling with line width (will not match with png
  output)
- Small optimizations for the text base line
- Bugfix text rotation versus shift
- Added more SVG filters
- Added checks for filter strings

Changes in Version 21-Jul-2009
- Improved bounding box calculation for filters
- Bugfixes for text size / line distance
- Support of background box for text
- Correct bounding box for text objects

Changes in Version 06-Mar-2010
- Improved support of filters
- Experimental support of animations
- Argument checks for filters
- Rework of tex string handling
- 'sub' and 'super' workaround for Firefox and Inkscape
- Bugfix for log axes (missing minor grid for some special
  cases)
- Bugfix nomy line #1102 (thanks to Pooya Jannaty)
- Bugfix minor tickmarks for log axis scaling (thanks to
  Harke Pera)
- Added more lex symbols
- Automatic correction of illegal axis scalings by the user
  (thanks to Juergen)
- Renamed plot2svg_beta to plot2svg

Limitations:
- axis scaling factors for 3D axes
- plot object of Matlab R14 not supported (use 'v6' switch instead)
- 3D plot functionality limited (depth sorting, light)

Example of a SVG file is included to the zip file.

Reports of bugs highly welcome.

MATLAB release MATLAB 6.5 (R13)
Zip File Content  
Other Files
license.txt,
plot2svg_20100306/demo_3d_plot2svg.m,
plot2svg_20100306/demo_svg_water.asv,
plot2svg_20100306/demo_svg_water.jpg,
plot2svg_20100306/demo_svg_water.m,
plot2svg_20100306/demo_svg_water.svg,
plot2svg_20100306/gradient.png,
plot2svg_20100306/license.txt,
plot2svg_20100306/matterhorn_small.jpg,
plot2svg_20100306/plot2svg.m,
plot2svg_20100306/plot2svg_depreciated.m,
plot2svg_20100306/readme.txt,
plot2svg_20100306/simulink2svg.m,
plot2svg_20100306/sphere.png,
plot2svg_20100306/sphere.svg,
plot2svg_20100306/sphere.svgz,
plot2svg_20100306/svgBoundingBox.m,
plot2svg_20100306/svgComposite.m,
plot2svg_20100306/svgGaussianBlur.m,
plot2svg_20100306/svgImage.m,
plot2svg_20100306/svgLuminanceToAlpha.m,
plot2svg_20100306/svgOffset.m,
plot2svg_20100306/svgSpecularLightingDistant.m,
plot2svg_20100306/svgTurbulence.m,
plot2svg_20100306/temperature_nicer.svg,
plot2svg_20100306/temperature_perfect.jpg,
plot2svg_20100306/temperature_perfect.svg,
plot2svg_20100306/temperature_standard.svg,
plot2svg_20100306/tutorial_filters.jpg,
plot2svg_20100306/tutorial_filters.m,
plot2svg_20100306/tutorial_filters.svg,
plot2svg_20100306/tutorial_plot2svg.m,
plot2svg_20100306/water_stones.jpg
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (73)
30 May 2005 Heiko Marx

Nice! What I first found was that for zoomed plots the data exceeds the plot area. And the files become quite large. And having lots of controls causes having lots of jpegs. But because we use the .svg-format very often, this is a very useful tool with a lot of potential! Thank you!

01 Nov 2005 tom mod  
01 Nov 2005 Charlie Eckelston

Great tool for editing plots for publications

06 Nov 2005 Matthias Schabel

Very nice work. Default plot size appears quite small when imported into Illustrator - 400% magnification required to make image fit standard page. Otherwise great help for preparing plots for publication.

08 Nov 2005 Wladimir van der Laan

You just saved my day :-) I tried so many things, like exporting .ai and trying to import it in inkscape, but it all yielded corrupted plots or nothing at all. With this program, it works perfectly.

21 Jan 2006 Ken Senior

Running the plot2svg command on my Windows XP R14SP3 gives the error:
??? Error: File: plot2svg.m Line: 1763 Column: 1
The function "get_projection" was closed
 with an 'end', but at least one other function definition was not.
 To avoid confusion when using nested functions,
 it is illegal to use both conventions in the same file.

10 Feb 2006 E Dinnat

Just tried the 3D functionality on a few samples. Works great. Excellent and very usefull function. Too bad light is not exported and interpolated shading is not excellent, but I guess that SVG (or any vector format) isn't suited for so complex rendering.

21 Feb 2006 Yordan Kyosev

Thank you Juerg!

24 Feb 2006 m m

Get confused if you manually alter the axis scales: e.g. Inkscape still reports layers of the 'original' size I think. Also non-size preserving in pixels at the least. Needs specifically size setting in e.g. Inkscape before external users will recognise the pixel size settings. Otherwise, very goodl

03 May 2006 Kris De Gussem

Should be part of Matlab itself

14 Jun 2006 Timothy Withheld

this piece of code is amazing. the svg exports work perfect with inkscape which is _exactly_ what i needed.

18 Oct 2006 Monsieur Truc

Thanks, this is great and should be implemented natively in Matlab.
Tip : if you want smaller files, convert the multilines objects (curves...) into pathes with inkscape and use the 'simplify' tool.

06 Nov 2006 S. Barth

Great! Spent too much time to find something comparable.

19 Jan 2007 Benjamin Watts

Excellent function, I will use this alot!

Bug: setting XTick with any numbers outside of the set xlim in the figure will cause an error in plot2svg.

08 Feb 2007 phox hat

Just what I needed!

28 Feb 2007 bass atallah

Works well for the most part. Gives an error and doesn't converst bar graphs though.

05 Mar 2007 J. V.

Hi

I don't see why doesn't Matlab have an "export to SVG" option yet. Juerg Schwizer did a great job, but it is too much for a single person to implement the full support for SVG.

It works ok for simple graphics. But it fails with transparencies and flat FaceColor. Take the example in the documentation for the "patch" command

vert = [0 1 1;0 2 1;1 2 1;1 1 1];
fac = [1 2 3;1 3 4];
tcolor = [1 1 1;.7 .7 .7];
patch('Faces',fac,'Vertices',vert,'FaceVertexCData',tcolor,'FaceColor','flat')

plot2svg 'matlab_patch_example.svg'

01 May 2007 Jean-Francois Dupuis

To handle bar plot, just use the backward compatibility flag such as : bar('v6', ...);

06 Jun 2007 bahram houchmandzadeh

Great work. For must stuff we do, matlab plots are not that sophisticated and the package just works.

22 Jun 2007 PONTHEP VENGSUNGNLE

Great job,It is very interesting
Thank for good experience
From thailand

25 Jun 2007 bassam atallah

Great little application. It is helpful. A few comments.
Doesn't seem to deal correctly with:
1) When background axis 'Color' is set to 'none' (you get a none white background)
2) Doesn't support histogram plots in the form of 'bar' or 'stairs'

20 Aug 2007 Stijn Klaassen

Great tool for exporting graphs to Inkscape!
Get an error when making a plot using errorbar:
"??? Input argument "projection" is undefined.Error in ==> plot2svg>axchild2svg at 706 [x,y,z] = project(linex,liney,linez,projection);
Error in ==> plot2svg>axchild2svg at 1121 group=axchild2svg(fid,id,axIdString,ax,group,paperpos,get(axchild(i), 'Children'),axpos,groupax);
Error in ==> plot2svg>axes2svg at 459
group = axchild2svg(fid,id,axIdString,ax,group,paperpos,axchild,axpos,groupax,projection);
Error in ==> plot2svg at 139 group=axes2svg(fid,id,ax(j),group,paperpos);"

Anybody an idea for a workaround?

06 Sep 2007 jhgjh ouyou  
07 Sep 2007 Frouke H

I got the following error message:
"??? Attempted to access xg_label_end(5); index out of bounds because numel(xg_label_end)=4.

Error in ==> plot2svg>axes2svg at 545
                    label2svg(fid,grouplabel,axpos,ax,xg_label_end(i),yg_label_end(i),convertString(axlabelx(i,:)),'Center',0,'top',1,paperpos,scolorname,exponent);

Error in ==> plot2svg at 139
        group=axes2svg(fid,id,ax(j),group,paperpos);"

What do I do wrong?

19 Sep 2007 Jarek Tuszynski

Great tool.

07 Nov 2007 Geoff Adams

Very nice function. However, I believe I have found a bug. On line 1121, "axchild2svg" is called without the "projection" argument. Adding it in seems to fix the problem. So to fix the bug:

--At line 1121, replace:
group=axchild2svg(fid,id,axIdString,ax,group,paperpos,get(axchild(i), 'Children'),axpos,groupax);
--with:
group=axchild2svg(fid,id,axIdString,ax,group,paperpos,get(axchild(i), 'Children'),axpos,groupax,projection);
--Done.

18 Dec 2007 Sam R

This is excellent. Matlab allows you to save figures in illustrator's format, but it does not handle transparency of 3D planes. This script does and makes it possible to have a vectorial file of 3D surfaces with transparency. Thanks!

28 Dec 2007 Kaushik Ghose

This is a great script! Thank you for making it.
I use inkscape to edit the svg files and I find the following issues:

1. I need to hand code the font into the file (i.e. I need to force
textfontname = 'Arial';
)

2. I need to remove the "pt" from all the font size descriptions

Thanks
-Kaushik

07 Feb 2008 r. h.

Bug report. Used without arguments.

??? Attempted to access cdata(2,:); index out of bounds because size(cdata)=[1,21].

Error in ==> plot2svg>gouraud_patch2svg at 1208
                face_color2 = cdata(j-1,:);

Error in ==> plot2svg>axchild2svg at 861
                gouraud_patch2svg(fid, group, axpos, x(faces(p,:)), y(faces(p,:)),
                cdata, linestyle, linewidth, edgecolorname, face_opacity,
                edge_opacity,id)

Error in ==> plot2svg>axes2svg at 459
group =
axchild2svg(fid,id,axIdString,ax,group,paperpos,axchild,axpos,groupax,projection);

Error in ==> plot2svg at 139
        group=axes2svg(fid,id,ax(j),group,paperpos);

10 Mar 2008 Jason Merrill

This is fantastic. I think this may allow me to dump Illustrator in favor of Inkscape. One cross-platform thing: on Unix/Mac, files always get saved with an extra backslash in front of them. A quick fix is to replace the explicit string '/' with filesep in the addBackSlash subfunction (lines 1652-1653 in plot2svg, and lines 1232-1233 in plot2svg_2d). Here's the corrected version:

function strString=addBackSlash( strSlash)
% adds a backslash at the last position of the string (if not already there)
if ( strSlash(end) ~= filesep)
    strString = [ strSlash filesep];
else
    strString = strSlash;
end

I suspect this could all be cleaned up (i.e. you wouldn't even need the addBackSlash function) using the fullfile function.

24 Apr 2008 nino guttuso  
15 May 2008 Dmitry Babin

Bug report (MATLAB R2008a, not tested with older versions):
1. LaTeX commands are not interpreted (e.g. \bf appears in SVG text strings)
2. When trying to use it with surf plots, the following error message appears:

??? Error using ==> get
There is no 'Units' property in the 'surfaceplot' class.

Error in ==> plot2svg at 87
originalFigureUnits=get(id,'Units');

18 May 2008 Mat Hunt

Interoperability with octave would also be a good idea, I get the error message (with octave):
   Matlab to SVG converter version 22-Jan-2006, Juerg Schwizer (converter@juergs
chwizer.de).
   Warning: Future versions may no more support older versions than MATLAB R12.
error: `uiputfile' undefined near line 52 column 29
error: evaluating if command near line 51, column 1
error: called from `plot2svg' in file `/home/mat/plot2svg.m'

24 May 2008 Dmitry Babin

A correction to my previous post (from 2008-05-15):

1. LaTeX commands ARE interpreted, but only when enclosed by curly braces. For example:
 xlabel('\bft\rm, [sec]')
isn't interpreted correctly;
 xlabel('{\bft}, [sec]')
is OK.

2. About "surf" and "mesh" plots: my mistake... I tried to use it in this way:
 h = surf(.........)
 plot2svg('filename.svg',h)
The correct way to get a handle is:
 h = figure(1)
 surf(.........)
 plot2svg('filename.svg',h)

02 Sep 2008 sylvain lalure  
12 Sep 2008 Mazen Saied

Hello,

Great work and congratulations for this macro. I have found a bug to correct. It concerns surface intersections when you plot 2 or more surfaces (surf, mesh, ...). I notices that when you export in SVG format, plotted surfaces are stacked one on the other and their intersections disappear.

Nevertheless, all the rest is perfect.
Thank you

16 Sep 2008 george melinkus

How long will it take The Mathworks to include this functionality in Matlab by default?! It has been asked multiple times and would be a BIG plus considering the growing support for the format, both closed and open source.

Just wondering... big thumbs up for the author of this export script!

04 Dec 2008 Georg Stillfried

very nice, works well

04 Dec 2008 Georg Stillfried

unfortunately I recieve an error when I try to export patch and surface objects (Matlab 7 on Linux)

>> plot2svg('figure.svg')
   Matlab to SVG converter version 22-Jan-2006, Juerg Schwizer (converter@juergschwizer.de).
??? Input argument "projection" is undefined.

Error in ==> plot2svg>axchild2svg at 902
            [x,y,z] = project(points(1,:),points(2,:),points(3,:),projection);

902 [x,y,z] = project(points(1,:),points(2,:),points(3,:),projection);

13 Feb 2009 Sebastien Besson

Hi Georg,

I experienced the same problem and solved it by replacing lines 1121 and 1130 :
group=axchild2svg(fid,id,axIdString,ax,group,paperpos,get(axchild(i), 'Children'),axpos,groupax);
by
group=axchild2svg(fid,id,axIdString,ax,group,paperpos,get(axchild(i), 'Children'),axpos,groupax,projection);

Hope it will help you.

22 Feb 2009 Mike Schachter

plot2svg doesn't work for higher MATLAB versions (such as 7.6), but here is a fix. Put this near the top of plot2svg_2d in order to make things work:

if (str2num(matversion(1)) >= 7)
    disp(' Using grandparent id due to higher matlab version.');
    id = get( get(id, 'Parent'), 'Parent');
end

22 Feb 2009 Mike Schachter

Just to be specific, you can paste that code at line 40 of plot2svg_2d.m.

22 Feb 2009 Mike Schachter

By the way, this is the most awesome and necessary script I've ever used. When it stopped working I wanted to die and thought the world around me was crumbling to pieces, leaving me shattered and vulnerable to the cruel biddings of Adobe Illustrator.

But now those days are over, I can breathe a breath of joy knowing that I can continue to use Inkscape for making figures! Hurrah!

22 Feb 2009 Mike Schachter

Sorry, kind of screwed up there - what I was trying to do was plot a handle that comes from a call to the polar(...) command. plot2svg works fine for figure handles. I retract my fix, but not the whole dying-without-plot2svg thing.

24 Apr 2009 Florian  
13 May 2009 Georg Stillfried

The advice by Sebastien Besson did the trick. Thanks!

23 May 2009 Ritesh Sood

found a little bug on line 823 of plot2svg_2d.m which was causing firefox to hit a parsing error. The original line code is
case '-.',pattern = 'stroke-dasharray="100pt,25pt,25pt,25pt,"';
which should be changed to
case '-.',pattern = 'stroke-dasharray="100pt,25pt,25pt,25pt"';
(The bug is the trailing `," after the last 25pt.)
---------------------------------------------------
There are a few issues that I'm seeing in the exported svg:
1) subscripted labels like "f(t_1,t_2)" are appearing verbatim; subscripts are not getting interpreted as I believe they should.
2) I have a figure with two 2D contour plots differentiated by one set of contours being solid and the other set dot-dashed. The svg output is unfortunately quite poor: one can hardly make out that there are two sets of contours.
----------------
For (1) above I have an idea: SVG+MathML
I am using MathML to render a table of parameters -- which requires some math typesetting, greek symbols, matrices -- to go along with the plots. The way I am doing that is to have tex (well, itex actually) markup in the file and pass the file through itex2MML.
Maybe the same process will work with the svg figures. Enclose the math in the labels in a pair of
`$"s (requited by itex), set Matlab's Interpreter to Latex so that the fig file comes out alright, create an svg and filter through itex2MML. Let's see how that goes.
If only Matlab had native SVG support, wouldn't have to jum through all these hoops...

16 Jun 2009 Benjamin

Bug report:
If I set ytick manually, but then also set ylim so that not all yticks are displayed, then I get an "Index exceeds matrix dimensions" error.

Fix:
line 1019 of plot2svg_2d:

indexnz=find(labelpos ~= 0)

should be changed to:

labellimit=get(ax,'YLim')
indexnz=find(labelpos ~= 0 & labelpos >= labellimit(1) & labelpos <= labellimit(2))

and obviously, line 1003 should be changed similarly for the x-axis case.

25 Jun 2009 Vincent

very usefull tool
It would be nice if someone could compile the bug fixes listed above and release a updated version... (probl. Juerg is already working on that...?)

12 Aug 2009 Cesar Roda Neve

I have found a bug. When i write in the axis label a text including super or sub script, just something like:

Text_{Material}

It just ignore the super or sub thing and write it together...

TextMaterial

It should be nice if someone has an idea of how to fix this.

12 Aug 2009 Juerg Schwizer

Hi Cesar Roda Neve,
This is not a bug in plot2svg. It's a limitation of Inkscape and Firefox. Other browsers like Opera or Chrome can handle it. The SVG code for sub and super script is conform to the SVG 1.1 specification. I'm aware of the limitation and will try to find a workaround for Inkscape and Firefox.

12 Aug 2009 T  
20 Aug 2009 Kristin B.  
03 Sep 2009 Eddie Seven

yay, it works. I wrap a rsvg-convert after it to get a png file. even for simple plots, it's scandalous how bad the matlab internal plot saving utilities are.

06 Sep 2009 me

great!
without this presenting results would suck!

btw.
in order to ensure utf 8 encoding, change two lines in plot2svg.m
:
142: fid=fopen(finalname,'wt', 'n', 'UTF-8'); % Create a new text file
143: fprintf(fid,'<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"&gt;\n'); % Insert file header

10 Oct 2009 Rob Campbell

I love it! I see I shall be using this a lot.
Seems to work very well in Firefox (all I've tried so far).
Am about to use it for generating HTML reports of analyses.

26 Oct 2009 Aslak Grinsted

I would like to use plot2svg for producing figures for publications. (I am often having problems with matlabs print when there is anything transparent in the plot.)

That means i would like to use absolute units for the size. I would also like to specify the font size, linewidth in units of points. Many journals have strict requirements on these.

14 Feb 2010 Zboud

Great, too bad LaTeX-interpreted text() results are not interpreted...and {} don't help, I get $v$ or {$v$} in the SVG file ... :'(

24 Feb 2010 Felix Zoergiebel

Great job! This really helps me plotting translucent patches, which is just not possible with matlab functions. However, there are small problems.
1: latex \cdot is not processed. I added
tex=strrep(tex,'\cdot','& # 8901;'); (without spaces...)
to line 2351 of plot2svg_beta.m
2: I have an hggroup with text objects that are placed outside of the axis (custom labels). These labels are not plotted before I set the parent of each of them to the axis.

24 Feb 2010 Felix Zoergiebel

Yet another bug when plotting the y-axis on the right side of the plot-box: label positions are inverted, i.e. labels are not [1 2 3 4 5] but [5 4 3 2 1] (data is still plotted as in figure)

28 Feb 2010 Juerg Schwizer

Hi Felix, many thanks for the feedback! Bug 1 is already implemented together with additional tex elements. These changes will soon be published together with a minor label bugfix. I was not able to reproduce bug 2 & 3. Could you please send me an example. Many thanks. Juerg.

02 Mar 2010 Juergen

Really great! Thanks a lot!

just one small problem with log scaled axes. To reproduce:
figure; plot(0:5, 0:5);
set(gca, 'xLim', [0 5]);
set(gca, 'xScale', 'log');
plot2svg

Solution: always set lower xLim > 0, if you use log scaled axes.
(I know: quite obvious! :-) ...but this case could simply come true)

I guess this exception could be trapped in function get_projection (around line 1913): if xi(1) == Inf ...

06 Mar 2010 Juerg Schwizer

% Example how to adjust your figure properties for
% publication needs (answer to Aslak Grinsted's question)
s = figure;
% Select the default font and font size
% Note: Matlab does internally round the font size
% to decimal pt values
set(s, 'DefaultTextFontSize', 10); % [pt]
set(s, 'DefaultAxesFontSize', 10); % [pt]
set(s, 'DefaultAxesFontName', 'Times New Roman');
set(s, 'DefaultTextFontName', 'Times New Roman');
% Select the preferred unit like inches, centimeters,
% or pixels
set(s, 'Units', 'centimeters');
pos = get(s, 'Position');
pos(3) = 8; % Select the width of the figure in [cm]
pos(4) = 6; % Select the height of the figure in [cm]
set(s, 'Position', pos);
set(s, 'PaperType', 'a4letter');
% From SVG 1.1. Specification:
% "1pt" equals "1.25px"
% "1pc" equals "15px"
% "1mm" would be "3.543307px"
% "1cm" equals "35.43307px"
% "1in" equals "90px"

02 Apr 2010 Gladnon Galoshev  
26 Apr 2010 Rahul  
09 May 2010 Patrick Mineault  
09 May 2010 Patrick Mineault

It didn't work immediately with a figure with a /patch/ (the outlines were correct but the colors didn't show up). Got it to work by switching to the /fill/ command instead. The output is exceedingly accurate compared with the eps exporters based on the painters renderer which tries to simplify/merge outlines and messes up a lot of small details. Excellent work!

10 May 2010 Patrick Mineault

Bug report:

I ran into trouble when attempting to use ImageMagick's convert command line program with an svg generated by plot2svg (e.g convert myplot.svg myplot.png). The aspect ratio of the output was way off. However when I loaded the same file in Illustrator it came out fine. Comparing Illustrator and plot2svg output, I found the following solution:

Replace line 176 with:

fprintf(fid,'<svg preserveAspectRatio="xMinYMin meet" width="%0.3fpx" height="%0.3fpx" viewBox="0 0 %0.3f %0.3f" ',paperpos(3),paperpos(4),paperpos(3),paperpos(4));

As an added bonus, I now get correct crop marks when I load the file in Illustrator.

12 May 2010 Ryan

Thank you! I was constantly adjusting figures in Inkscape that did not copy properly from Matlab. Problem soved!

18 May 2010 Brock

By far one of the most useful pieces of code I've come across. I used to trace Bezier curves on top of .png images *by hand* in a vector graphics editor to get .svg images for papers and posters. I can't even begin to describe how much time/frustration this will save me! Thanks so much!

26 May 2010 Jonathon Harding

This is working excellently for me! I can finally output graphs in vector format with fonts other than Helvetica.

One minor bug report: (La)TeX strings that end with a single character after the last curly brace will drop that character (e.g. a_{sub}b would only display a_{sub}).

This can be fixed by changing line 2613 to:
if lastValidCharacter <= length(StringText)
The important part is the less than or equals, rather than a strict less than.

09 Jun 2010 Yohai

Works great for simple plots.
However, it doesn't work for pcolor. It creates a big file (11M) which doesn't look like the figure I've created.
Can it be a Linux-compatability problem?

02 Aug 2010 Eric Tittley  
Please login to add a comment or rating.
Updates
23 May 2005

Updated Version 22-May-2005
- bugfix line color
- bugfix path of linked jpeg figures
- improved patch handling
- support of pcolor plots

23 May 2005

Updated Version 22-May-2005
- bugfix line color
- bugfix path of linked jpeg figures
- improved patch handling
- support of pcolor plots

08 Dec 2005

Changes of Version 12-Dec-2005
- bugfix for Firefox 1.5
- improvement of the axis scaling
- improvement handling of exponents
- bugfix axindex
- bugfix cell array cells
- improved handling of pixel images
- improved markers

09 Jan 2006

3D Version
PLEASE UPDATE FILE AND DESCRIPTION

20 Jan 2006

New version supporting 3D plots

(please replace zip file and description)

Many thanks
Juerg Schwizer

24 Jan 2006

Important bugfix solving the problem described in the last rating.

Many thanks
Juerg Schwizer

30 Jun 2009

Several bugfixes and better support of 3D graphics

15 Jul 2009

Bugfixes and preliminary support of SVG filters, clipping, and improved axis tick labels.

20 Jul 2009

Improved SVG filter support, bugfixes, improved text support, more examples for the advanced filter usage.

16 Aug 2009

- Bug fixes for text size / line distance
- Support of background box for text
- Improved support of filters
- Experimental support of animations
- Rework of latex string handling
- 'sub' and 'super' workaround for Firefox and Inkscape

06 Mar 2010

Bugfixes and support of user requests. See 'Changes in Version 06-Mar-2010' for more information.

Tag Activity for this File
Tag Applied By Date/Time
specialized Juerg Schwizer 22 Oct 2008 07:45:21
plotting Juerg Schwizer 22 Oct 2008 07:45:21
svg Juerg Schwizer 22 Oct 2008 07:45:21
converter Juerg Schwizer 22 Oct 2008 07:45:21
plot2svg Juerg Schwizer 22 Oct 2008 07:45:21
figure Juerg Schwizer 22 Oct 2008 07:45:21
scalable Juerg Schwizer 22 Oct 2008 07:45:21
vector Juerg Schwizer 22 Oct 2008 07:45:21
graphics Juerg Schwizer 22 Oct 2008 07:45:21
3d Georg Stillfried 04 Dec 2008 07:42:12
data export Juerg Schwizer 01 Jul 2009 11:32:21
shadow Juerg Schwizer 15 Jul 2009 10:54:57
shade Juerg Schwizer 15 Jul 2009 10:54:57
svg filters Juerg Schwizer 15 Jul 2009 10:54:57
blur Juerg Schwizer 15 Jul 2009 10:54:57
light Juerg Schwizer 15 Jul 2009 10:54:58
animation Juerg Schwizer 17 Aug 2009 10:39:33
svg filters Sebastien Besson 26 Aug 2009 18:04:47

Contact us at files@mathworks.com