├── README.md
├── example
├── demo_3d_plot2svg.m
├── demo_svg_water.m
├── gradient.png
├── matterhorn_small.jpg
├── output
│ ├── demo_svg_water.jpg
│ ├── demo_svg_water.svg
│ ├── sphere.png
│ ├── sphere.svg
│ ├── sphere.svgz
│ ├── temperature_nicer.svg
│ ├── temperature_perfect.jpg
│ ├── temperature_perfect.svg
│ ├── temperature_standard.svg
│ ├── tutorial_filters.jpg
│ └── tutorial_filters.svg
├── tutorial_filters.m
├── tutorial_plot2svg.m
└── water_stones.jpg
├── license.txt
└── src
├── plot2svg.m
├── simulink2svg.m
├── svgBoundingBox.m
├── svgComposite.m
├── svgGaussianBlur.m
├── svgImage.m
├── svgLuminanceToAlpha.m
├── svgOffset.m
├── svgSpecularLightingDistant.m
└── svgTurbulence.m
/README.md:
--------------------------------------------------------------------------------
1 | Scalable Vector Graphics (SVG) Export of Figures
2 |
3 | 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.
4 |
5 | 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.
6 |
7 | Editors for the SVG file format can be found at http://www.inkscape.org.
8 |
9 | Usage:
10 | > plot2svg % opens a file dialog to plot the active figure
11 | or
12 | > plot2svg('myfile.svg', figure handle, pixelfiletype)
13 |
14 | pixelfiletype = 'png' (default), 'jpg'
15 |
16 | Supported Features
17 | - line, patch, contour, contourf, quiver, surf, ...
18 | - markers
19 | - image (saved as linked png pictures)
20 | - grouping of elements
21 | - alpha values for patches
22 | - subplot
23 | - colorbar
24 | - legend
25 | - zoom
26 | - reverse axes
27 | - controls are saved as png pictures
28 | - log axis scaling
29 | - axis scaling factors (10^x)
30 | - labels that contain Latex commands are interpreted (with some limitations):
31 | \alpha, \Alpha, \beta, \Beta, ... \infity, \pm, \approx
32 | {\it.....} for italic text
33 | {\bf.....} for bold text
34 | ^{...} for superscript
35 | _{...} for subscript
36 |
37 | How to use SVG files in HTML code
38 |
39 |
40 | Changes in Version 22-May-2005
41 | - bugfix line color
42 | - bugfix path of linked jpeg figures
43 | - improved patch handling (interpolation and texture still missing, preliminary depth sorting)
44 | - support of pcolor plots
45 | - preliminary: surface plots are projected on the xy-plane (use 'rotate' command)
46 |
47 | Changes in Version 12-Dec-2005
48 | - bugfix viewBox
49 | - improvement of the axis scaling (many thanks to Bill Denney)
50 | - improvement handling of exponents for log-plots
51 | - default pixel format png instead of jpeg (many thanks to Bill Denney)
52 | - bugfix axindex
53 | - bugfix cell array cells (many thanks to Bill Denney)
54 | - improved handling of pixel images (many thanks to Bill Denney)
55 | - to save original figure background use set(gcf,'InvertHardcopy','off')
56 | - improved markers
57 |
58 | Changes in Version 8-Jan-2006
59 | - axes handling fully reworked (3D axes)
60 | - rework of axes scaling (3D axes)
61 | - clipping enabled (Use carefully, as all figure data is written to file -> may get large)
62 | - minor grid lines are now supported for linear and log plots
63 | - linear color interpolation on patches (The interploation needs to be emulated as SVG does not support a linear interpolation of colors between three points. This is done by combination of different patches with linear alpha gradients. See limitation for Firefox 1.5.)
64 |
65 | Changes in Version 20-Jun-2009
66 | - Bugfix '°','±','µ','²','³','¼''½','¾','©''®'
67 | - Bugfix 'projection' in hggroup and hgtransform
68 | - Added Octave functionality (thanks to Jakob Malm)
69 | Bugfixe cdatamapping (thanks to Tom)
70 | Bugfix image data writing (thanks to Tom)
71 | Patches includes now markers as well (needed for 'scatter'
72 | plots (thanks to Phil)
73 | - Bugfix markers for Octave (thanks to Jakob Malm)
74 | - Bugfix image scaling and orientation
75 | Bugfix correct backslash (thanks to Jason Merril)
76 | - Improvment of image handling (still some remaining issues)
77 | Fix for -. line style (thanks to Ritesh Sood)
78 |
79 | Changes in Version 28-Jun-2009
80 | - Improved depth sorting for patches and surface
81 | - Bugfix patches
82 | - Bugfix 3D axis handling
83 |
84 | Changes in Version 11-Jul-2009
85 | - Support of FontWeight and FontAngle properties
86 | - Improved markers (polygon instead of polyline for closed markers)
87 | - Added character encoding entry to be fully SVG 1.1 conform
88 |
89 | Changes in Version 13-Jul-2009
90 | - Support of rectangle for 2D
91 | - Added preliminary support for SVG filters
92 | - Added preliminary support for clipping with pathes
93 | - Added preliminary support for turning axis tickmarks
94 |
95 | Changes in Version 18-Jul-2009
96 | - Line style scaling with line width (will not match with png
97 | output)
98 | - Small optimizations for the text base line
99 | - Bugfix text rotation versus shift
100 | - Added more SVG filters
101 | - Added checks for filter strings
102 |
103 | Changes in Version 21-Jul-2009
104 | - Improved bounding box calculation for filters
105 | - Bugfixes for text size / line distance
106 | - Support of background box for text
107 | - Correct bounding box for text objects
108 |
109 | Changes in Version 06-Mar-2010
110 | - Improved support of filters
111 | - Experimental support of animations
112 | - Argument checks for filters
113 | - Rework of tex string handling
114 | - 'sub' and 'super' workaround for Firefox and Inkscape
115 | - Bugfix for log axes (missing minor grid for some special
116 | cases)
117 | - Bugfix nomy line #1102 (thanks to Pooya Jannaty)
118 | - Bugfix minor tickmarks for log axis scaling (thanks to
119 | Harke Pera)
120 | - Added more lex symbols
121 | - Automatic correction of illegal axis scalings by the user
122 | (thanks to Juergen)
123 | - Renamed plot2svg_beta to plot2svg
124 |
125 | Changes in Version 12-04-2010
126 | - Improved Octave compatibility
127 |
128 | Changes in Version 05-05-2010
129 | - Bugfix for ticklabels outside of the axis limits (thanks to
130 | Ben Scandella)
131 |
132 | Changes in Version 30-10-2010
133 | - Improved handling of empty cells for labels (thanks to
134 | Constantine)
135 | - Improved HTML character coding (thanks to David Mack)
136 | - Bugfix for last ')' (thanks to Jonathon Harding and Benjamin)
137 | - Enabled scatter plots using hggroups
138 | - Closing patches if they do not contain NaNs
139 |
140 | Changes in Version 10-11-2010
141 | - Support of the 'Layer' keyword to but the grid on top of
142 | of the other axis content using 'top' (Many thanks to Justin
143 | Ashmall)
144 | - Tiny optimization of the grid display at axis borders
145 |
146 | Changes in Version 25-08-2011
147 | - Fix for degree character (thanks to Manes Recheis)
148 | - Fix for problems with dash-arrays in Inkscape (thanks to
149 | Rüdiger Stirnberg)
150 | - Modified shape of driangles (thanks to Rüdiger Stirnberg)
151 |
152 | Changes in Version 22-10-2011
153 | - Removed versn as return value of function fileparts (thanks
154 | to Andrew Scott)
155 | - Fix for images (thanks to Roeland)
156 |
157 | Changes in Version 20-05-2012
158 | - Added some security checks for empty data
159 | - Fixed rotation for multiline text
160 |
161 | Changes in Version 25-08-2012
162 | - Special handling of 1xn char arrays for tick labels
163 | (thanks to David Plavcan)
164 | - Fix for 'Index exceeds matrix dimensions' of axis labels
165 | (thanks to Aslak Grinsted)
166 | - Fix for another axis label problem (thanks to Ben Mitch)
167 |
168 | Changes in Version 15-09-2012
169 | - Fix for linestyle none of rectangles (thanks to Andrew)
170 | - Enabled scatter plot functionality
171 |
172 | Limitations:
173 | - axis scaling factors for 3D axes
174 | - 3D plot functionality limited (depth sorting, light)
175 |
176 | Example of a SVG file is included to the zip file.
177 |
178 | Reports of bugs highly welcome.
179 |
--------------------------------------------------------------------------------
/example/demo_3d_plot2svg.m:
--------------------------------------------------------------------------------
1 | figure
2 | [x y z] = sphere(20);
3 | s = surface(x,y,z,'facecolor','interp','cdata',z);
4 | set(s,'edgecolor','black','facealpha','flat','alphadata',x.*z);
5 | alpha('scaled');
6 | axis equal
7 | box on
8 | grid on
9 | campos([2 13 10]);
10 | xlabel('X');
11 | ylabel('Y');
12 | zlabel('Z');
13 | title('Sphere with Alpha Data');
14 | plot2svg('sphere.svg');
15 |
--------------------------------------------------------------------------------
/example/demo_svg_water.m:
--------------------------------------------------------------------------------
1 | function demo_svg_water
2 | % Create a new figure and remember the figure handle
3 | fig = figure;
4 | % Set default font and font size
5 | set(fig, 'DefaultAxesFontName', 'Arial')
6 | set(fig, 'DefaultAxesFontSize', 16)
7 | % This is the data [year water_consumption]
8 | data = [
9 | 1980 230
10 | 1982 265
11 | 1984 265
12 | 1986 266
13 | 1988 262
14 | 1990 259
15 | 1992 277
16 | 1994 247
17 | 1996 238
18 | 1998 250
19 | 2000 250
20 | 2002 235
21 | 2004 233
22 | 2006 228
23 | ];
24 | % Let's plot the data
25 | hold on
26 | s = bar(data(:, 1), data(:, 2));
27 | % We do not want to apply the filter to the edge of the bars. Therefore, we
28 | % plot them in addition on top
29 | h = bar(data(:, 1), data(:, 2));
30 | set(h, 'FaceColor', 'none');
31 | set(h, 'EdgeColor', 'black');
32 | % Add the text inside each bar with correct rotation and alignment
33 | t = text(data(:, 1), data(:, 2) - 10, num2str(data(:, 2)));
34 | set(t, 'Rotation', -90);
35 | set(t, 'FontSize', 16);
36 | set(t, 'FontName', 'Arial');
37 | set(t, 'VerticalAlignment', 'middle');
38 | set(t, 'FontWeight', 'bold');
39 | % Adding labels and tick marks
40 | axis([1979 2008 0 400])
41 | set(gca, 'XTick', data(:, 1));
42 | set(gca, 'XTickLabel', num2str(data(:, 1)));
43 | title('Water Consumption per Person and Year')
44 | ylabel('Water consumption [l]')
45 | grid on
46 | box on
47 | set(gca, 'Position', [0.13 0.17 0.80 0.72]);
48 | % Now we add the filters
49 | % The bounding box with extension axes makes sure that we cover the full
50 | % axis region with the background images. Due to the shadow we have to
51 | % define an overlap region of 12px. Otherwise, distortions at the border of
52 | % the axis reagion may be visible.
53 | svgBoundingBox(s, 'axes', 12, 'off');
54 | % Now we add the image. To keep the aspect ratio we use 'xMidYMid slice'.
55 | % This setting centers the picture for both x and y. The kewyord 'slice'
56 | % makes sure that the picture is scaled so that the full axis region is
57 | % covered.
58 | svgImage(s, 'water_stones.jpg', 'xMidYMid slice', 'pic');
59 | % Create a composite between bars and picture by union.
60 | svgComposite(s, 'pic', 'SourceGraphic', 'atop', 'obj');
61 | % To create the shadow we use the bars and use a blur filter
62 | svgGaussianBlur(s, 'SourceAlpha', 5, 'blur');
63 | % The blurred bars are now shifted by [10 10].
64 | svgOffset(s, 'blur', [10 10], 'shade');
65 | % Combine the shadow and 'picture bars' by applying the later on top of the
66 | % shadow.
67 | svgComposite(s, 'obj', 'shade', 'over', 'front');
68 | % For the background we use the same picture but make it brighter
69 | svgComposite(s, 'pic', 'pic', 'arithmetic', 'background', [0 0.2 0 0]);
70 | % As last step, we combine the foreground and background
71 | svgComposite(s, 'front', 'background', 'over', 'final');
72 | % Beautify the tick mark labels by rotating them by 90 deg
73 | setting.svg.XTickLabelAngle = -90;
74 | set(gca, 'UserData', setting);
75 | % Finally, we save the result into a SVG file
76 | plot2svg('demo_svg_water.svg')
--------------------------------------------------------------------------------
/example/gradient.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jschwizer99/plot2svg/47a3970960ffcb327f13c744525e1ce8d3fcbd8d/example/gradient.png
--------------------------------------------------------------------------------
/example/matterhorn_small.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jschwizer99/plot2svg/47a3970960ffcb327f13c744525e1ce8d3fcbd8d/example/matterhorn_small.jpg
--------------------------------------------------------------------------------
/example/output/demo_svg_water.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jschwizer99/plot2svg/47a3970960ffcb327f13c744525e1ce8d3fcbd8d/example/output/demo_svg_water.jpg
--------------------------------------------------------------------------------
/example/output/demo_svg_water.svg:
--------------------------------------------------------------------------------
1 |
2 |
356 |
--------------------------------------------------------------------------------
/example/output/sphere.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jschwizer99/plot2svg/47a3970960ffcb327f13c744525e1ce8d3fcbd8d/example/output/sphere.png
--------------------------------------------------------------------------------
/example/output/sphere.svgz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jschwizer99/plot2svg/47a3970960ffcb327f13c744525e1ce8d3fcbd8d/example/output/sphere.svgz
--------------------------------------------------------------------------------
/example/output/temperature_nicer.svg:
--------------------------------------------------------------------------------
1 |
2 |
407 |
--------------------------------------------------------------------------------
/example/output/temperature_perfect.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jschwizer99/plot2svg/47a3970960ffcb327f13c744525e1ce8d3fcbd8d/example/output/temperature_perfect.jpg
--------------------------------------------------------------------------------
/example/output/temperature_perfect.svg:
--------------------------------------------------------------------------------
1 |
2 |
497 |
--------------------------------------------------------------------------------
/example/output/temperature_standard.svg:
--------------------------------------------------------------------------------
1 |
2 |
290 |
--------------------------------------------------------------------------------
/example/output/tutorial_filters.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jschwizer99/plot2svg/47a3970960ffcb327f13c744525e1ce8d3fcbd8d/example/output/tutorial_filters.jpg
--------------------------------------------------------------------------------
/example/tutorial_filters.m:
--------------------------------------------------------------------------------
1 | function tutorial_filters
2 | file = 'matterhorn_small.jpg';
3 | fig = figure;
4 | set(fig, 'DefaultAxesFontName', 'Arial')
5 | set(fig, 'DefaultAxesFontSize', 6)
6 | plotCounter = 1;
7 | xPlots = 3;
8 | yPlots = 4;
9 | % a) Original plot with a line, patch, and text object
10 | subplot(yPlots, xPlots, plotCounter)
11 | plotCounter = plotCounter + 1;
12 | h = create_plot;
13 | title('a) Original')
14 | % b) Adding a Gaussian blur filter for each object that uses the standard
15 | % color channels for the blur operation. The bounding box is covering
16 | % the axis region for each object. Note: there is no bounding box
17 | % overlap specified. This would lead to some distortion at the border if
18 | % a offset filter followed the blur filter.
19 | subplot(yPlots, xPlots, plotCounter)
20 | plotCounter = plotCounter + 1;
21 | h = create_plot;
22 | svgBoundingBox(h, 'axes', 0, 'off')
23 | svgGaussianBlur(h, 'SourceGraphic', 2, 'blur');
24 | title('b) Blur on (S = SourceGraphic)')
25 | % c) Identical to b) but the blur filter uses the alpha channel. This mode
26 | % is very useful to create shadows.
27 | subplot(yPlots, xPlots, plotCounter)
28 | plotCounter = plotCounter + 1;
29 | h = create_plot;
30 | svgBoundingBox(h, 'axes', 0, 'off')
31 | svgGaussianBlur(h, 'SourceAlpha', 2, 'blur');
32 | title('c) Blur (S = SourceAlpha)')
33 | % d) Adding a image filter that covers the whole axis region. The filter
34 | % replaces the object as no other combine filter is defined. The image
35 | % is scaled to the bounding box. This leads to a distortion of the
36 | % aspect ratio.
37 | subplot(yPlots, xPlots, plotCounter)
38 | plotCounter = plotCounter + 1;
39 | h = create_plot;
40 | svgBoundingBox(h, 'axes', 0, 'on')
41 | svgImage(h, file, 'none', 'pic');
42 | title('d) Pict (BB = axes, none)')
43 | % e) Identical to d) but with correct aspect ratio of the image. The
44 | % setting 'xMidYMid slice' centers the image and scales x and y so that
45 | % both cover the bonding box region defined by the axis region. The
46 | % clipping of the axis object removes the overlap.
47 | subplot(yPlots, xPlots, plotCounter)
48 | plotCounter = plotCounter + 1;
49 | h = create_plot;
50 | svgBoundingBox(h, 'axes', 0, 'on')
51 | svgImage(h, file, 'xMidYMid slice', 'pic');
52 | title('e) Pict (BB = axes, xMidYMid slice)')
53 | % f) Identical to e) but with image scaling 'xMidYMid meet'. This setting
54 | % also conserves the aspect ratio. However, the image may no more cover
55 | % the whole bounding box.
56 | subplot(yPlots, xPlots, plotCounter)
57 | plotCounter = plotCounter + 1;
58 | h = create_plot;
59 | svgBoundingBox(h, 'axes', 0, 'on')
60 | svgImage(h, file, 'xMidYMid meet', 'pic');
61 | title('f) Pict (BB = axes, xMidYMid meet)')
62 | % h) Identical to f) but with bounding box defined by the object. The
63 | % bounding box may be larger than the object extension due to line
64 | % width and marker size.
65 | subplot(yPlots, xPlots, plotCounter)
66 | plotCounter = plotCounter + 1;
67 | h = create_plot;
68 | svgBoundingBox(h, 'element', 0, 'on')
69 | svgImage(h, file, 'xMidYMid meet', 'pic');
70 | title('g) Pict (BB = element, xMidYMid meet)')
71 | % g) Now we add a composite filter that combines the filter result from the
72 | % image filter and the source graphic. The keyword 'atop' restricts the
73 | % image filter to the object boundaries.
74 | subplot(yPlots, xPlots, plotCounter)
75 | plotCounter = plotCounter + 1;
76 | h = create_plot;
77 | svgBoundingBox(h, 'axes', 0, 'on')
78 | svgImage(h, file, 'xMidYMid slice', 'pic');
79 | svgComposite(h, 'pic', 'SourceGraphic', 'atop', 'obj');
80 | title('h) Pict (BB = axes, xMidYMid slice)')
81 | % i) Identical to g) but with a filter bounding box defined by the object
82 | % extension. The image scaling 'xMidYMid meet' is not well suited for
83 | % this application. The image is not covering the whole object.
84 | subplot(yPlots, xPlots, plotCounter)
85 | plotCounter = plotCounter + 1;
86 | h = create_plot;
87 | svgBoundingBox(h, 'element', 0, 'on')
88 | svgImage(h, file, 'xMidYMid meet', 'pic');
89 | svgComposite(h, 'pic', 'SourceGraphic', 'atop', 'obj');
90 | title('i) Pict (BB = element, xMidYMid meet)')
91 | % j) Identical to i) but with a better image scaling that conserves the
92 | % spect ratio and makes sure that the whole bounding box is covered.
93 | subplot(yPlots, xPlots, plotCounter)
94 | plotCounter = plotCounter + 1;
95 | h = create_plot;
96 | svgBoundingBox(h, 'element', 0, 'on')
97 | svgImage(h, file, 'xMidYMid slice', 'pic');
98 | svgComposite(h, 'pic', 'SourceGraphic', 'atop', 'obj');
99 | title('j) Pict (BB = element, xMidYMid slice)')
100 | % k) Identical to j) but with a bounding box overlap of 5 pixel. This is
101 | % important to avoid distortions at the border.
102 | subplot(yPlots, xPlots, plotCounter)
103 | plotCounter = plotCounter + 1;
104 | h = create_plot;
105 | svgBoundingBox(h, 'element', 5, 'on')
106 | svgImage(h, file, 'xMidYMid slice', 'pic');
107 | svgComposite(h, 'pic', 'SourceGraphic', 'atop', 'obj');
108 | title('k) Pict (BB = element, xMidYMid slice)')
109 | % l) Identical to k) but the composition is based on the image filter and a
110 | % blur filter. In addition, the image filter covers the whole axis
111 | % region.
112 | subplot(yPlots, xPlots, plotCounter)
113 | plotCounter = plotCounter + 1;
114 | h = create_plot;
115 | svgBoundingBox(h, 'axes', 0, 'on')
116 | svgImage(h, file, 'xMidYMid slice', 'pic');
117 | svgGaussianBlur(h, 'SourceAlpha', 2, 'blur');
118 | svgComposite(h, 'pic', 'blur', 'atop', 'obj');
119 | title('l) Blur + Pict (BB = axes, xMidYMid slice)')
120 | % Save the result
121 | plot2svg('tutorial_filters.svg')
122 |
123 | function handles = create_plot
124 | % Helper function to plot the objects
125 | hold on
126 | s1 = text(3, 1, 'plot2svg', 'FontName', 'Arial', 'FontSize', 16, ...
127 | 'Color', 'red', 'FontWeight', 'bold', 'Margin', 0.01, 'Clipping', 'on');
128 | s2 = plot([6 8], [3 6], 'b', 'LineWidth', 20);
129 | s3 = patch([1 2 3 4 3 2 1], [1 3 2 3 4 5 3],'black');
130 | handles = [s1 s2 s3];
131 | box on
132 | grid on
133 | axis([0 10 0 6])
134 |
--------------------------------------------------------------------------------
/example/tutorial_plot2svg.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jschwizer99/plot2svg/47a3970960ffcb327f13c744525e1ce8d3fcbd8d/example/tutorial_plot2svg.m
--------------------------------------------------------------------------------
/example/water_stones.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jschwizer99/plot2svg/47a3970960ffcb327f13c744525e1ce8d3fcbd8d/example/water_stones.jpg
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2005, Juerg Schwizer
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are
6 | met:
7 |
8 | * Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | * Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in
12 | the documentation and/or other materials provided with the distribution
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 | POSSIBILITY OF SUCH DAMAGE.
25 |
--------------------------------------------------------------------------------
/src/plot2svg.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jschwizer99/plot2svg/47a3970960ffcb327f13c744525e1ce8d3fcbd8d/src/plot2svg.m
--------------------------------------------------------------------------------
/src/simulink2svg.m:
--------------------------------------------------------------------------------
1 | function simulink2svg
2 | % Show the hidden handles to get access to the simulink figures
3 | set(0,'ShowHiddenHandles','on');
4 | % Iterate over all children of the root
5 | child = get(0,'children');
6 | for i = 1:length(child)
7 | % Pick all scope figures
8 | if strcmp(get(child(i),'Tag'),'SIMULINK_SIMSCOPE_FIGURE')
9 | % In order to get the correct background turn inverted background
10 | % off. If you like a white background you should invert all labels
11 | % and lines.
12 | set(child(i),'InvertHardcopy','off');
13 | % Use plot2svg
14 | plot2svg(['Scope_' num2str(i) '.svg'], child(i))
15 | set(0,'ShowHiddenHandles','off')
16 | end
17 | end
--------------------------------------------------------------------------------
/src/svgBoundingBox.m:
--------------------------------------------------------------------------------
1 | function svgBoundingBox(s, type, overlap, visible)
2 | % Configures the bounding box of a SVG filter
3 | % PRELIMINARY IMPLEMENTATION (Parameters may change)
4 | %
5 | % svgBoundingBox(s, type, overlap, visible)
6 | % Parameters:
7 | % s : Array of plot object handles
8 | % type : [axes, element, relative]
9 | % Sets the filter bounding box to cover the axis reagion (axes), the
10 | % element extension (element or relative). Axes gives usually the
11 | % best results but may be slower.
12 | % overlap : Many filters need an overlap to work correctly.
13 | % Typical values for type 'axes' and 'element' -> 10
14 | % Typical values for type 'relative' -> 0.1
15 | % visible : Debugging functionality to see the bounding box used for an
16 | % object
17 | for i = 1:length(s)
18 | userdata = get(s(i),'UserData');
19 | userdata.svg.BoundingBox.Visible = visible; % Useful for debugging of bounding box for filters
20 | userdata.svg.BoundingBox.Type = type; % [axes, element, relative]
21 | userdata.svg.BoundingBox.Overlap = overlap;
22 | set(s(i),'UserData', userdata);
23 | end
24 |
--------------------------------------------------------------------------------
/src/svgComposite.m:
--------------------------------------------------------------------------------
1 | function svgComposite(s, source1, source2, operator, result, k)
2 | % Adds a feComposite SVG filter
3 | % PRELIMINARY IMPLEMENTATION (Parameters may change)
4 | %
5 | % svgComposite(s, source1, source2, operator, result)
6 | % Parameters:
7 | % s : Array of plot object handles
8 | % source1 : Any previous defined filter result string, 'SourceGraphic',
9 | % or 'SourceAlpha'.
10 | % source2 : Any previous defined filter result string, 'SourceGraphic',
11 | % or 'SourceAlpha'.
12 | % operator : Operator 'over','in','out','atop','xor','arithmetic'
13 | % -> see SVG 1.1 specification. 'arithmetic' is not yet
14 | % supported.
15 | % result : String that identifies the filter result for following filter
16 | % stages.
17 | for i = 1:length(s)
18 | userdata = get(s(i),'UserData');
19 | if isfield(userdata, 'svg') && isfield(userdata.svg, 'Filter')
20 | next = length(userdata.svg.Filter) + 1;
21 | else
22 | next = 1;
23 | end
24 | userdata.svg.Filter(next).Subfilter.Type = 'feComposite';
25 | userdata.svg.Filter(next).Subfilter.Source1 = source1;
26 | userdata.svg.Filter(next).Subfilter.Source2 = source2;
27 | userdata.svg.Filter(next).Subfilter.Operator = operator;
28 | if nargin > 5
29 | userdata.svg.Filter(next).Subfilter.k = k;
30 | end
31 | userdata.svg.Filter(next).Subfilter.Result = result;
32 | set(s(i),'UserData', userdata);
33 | end
--------------------------------------------------------------------------------
/src/svgGaussianBlur.m:
--------------------------------------------------------------------------------
1 | function svgGaussianBlur(s, source, deviation, result)
2 | % Adds a feGaussianBlur SVG filter
3 | % PRELIMINARY IMPLEMENTATION (Parameters may change)
4 | %
5 | % svgGaussianBlur(s, source, deviation, result)
6 | % Parameters:
7 | % s : Array of plot object handles
8 | % source : Any previous defined filter result string, 'SourceGraphic',
9 | % or 'SourceAlpha'.
10 | % deviation : Blur strength
11 | % result : String that identifies the filter result for following filter
12 | % stages.
13 | for i = 1:length(s)
14 | userdata = get(s(i),'UserData');
15 | if isfield(userdata, 'svg') && isfield(userdata.svg, 'Filter')
16 | next = length(userdata.svg.Filter) + 1;
17 | else
18 | next = 1;
19 | end
20 | userdata.svg.Filter(next).Subfilter.Type = 'feGaussianBlur';
21 | userdata.svg.Filter(next).Subfilter.Deviation = deviation;
22 | userdata.svg.Filter(next).Subfilter.Source = source;
23 | userdata.svg.Filter(next).Subfilter.Result = result;
24 | set(s(i),'UserData', userdata);
25 | end
26 |
--------------------------------------------------------------------------------
/src/svgImage.m:
--------------------------------------------------------------------------------
1 | function svgImage(s, file, aspectRatio, result)
2 | % Adds a feImage SVG filter
3 | % PRELIMINARY IMPLEMENTATION (Parameters may change)
4 | %
5 | % svgImage(s, file, aspectRatio, result)
6 | % Parameters:
7 | % s : Array of plot object handles
8 | % file : Pixel graphics file name (png or jpeg) with extension.
9 | % aspectRatio: 'none' -> scale to bounding box limits
10 | % 'xMinYMin meet', 'xMinYMin slice', 'xMidYMid meet', ...
11 | % -> see SVG 1.1 specification
12 | % result : String that identifies the filter result for following filter
13 | % stages.
14 | for i = 1:length(s)
15 | userdata = get(s(i),'UserData');
16 | if isfield(userdata, 'svg') && isfield(userdata.svg, 'Filter')
17 | next = length(userdata.svg.Filter) + 1;
18 | else
19 | next = 1;
20 | end
21 | userdata.svg.Filter(next).Subfilter.Type = 'feImage';
22 | userdata.svg.Filter(next).Subfilter.File = file;
23 | userdata.svg.Filter(next).Subfilter.AspectRatio = aspectRatio;
24 | userdata.svg.Filter(next).Subfilter.Result = result;
25 | set(s(i),'UserData', userdata);
26 | end
27 |
--------------------------------------------------------------------------------
/src/svgLuminanceToAlpha.m:
--------------------------------------------------------------------------------
1 | function svgLuminanceToAlpha(s, source, result)
2 | % Adds a feColorMatrix SVG filter that maps luminance to alpha values
3 | % PRELIMINARY IMPLEMENTATION (Parameters may change)
4 | %
5 | % svgLuminanceToAlpha(s, source, result)
6 | % Parameters:
7 | % s : Array of plot object handles
8 | % source : Any previous defined filter result string, 'SourceGraphic',
9 | % or 'SourceAlpha'.
10 | % result : String that identifies the filter result for following filter
11 | % stages.
12 | for i = 1:length(s)
13 | userdata = get(s(i),'UserData');
14 | if isfield(userdata, 'svg') && isfield(userdata.svg, 'Filter')
15 | next = length(userdata.svg.Filter) + 1;
16 | else
17 | next = 1;
18 | end
19 | userdata.svg.Filter(next).Subfilter.Type = 'feColorMatrix';
20 | userdata.svg.Filter(next).Subfilter.Source = source;
21 | userdata.svg.Filter(next).Subfilter.Result = result;
22 | userdata.svg.Filter(next).Subfilter.ColorType = 'luminanceToAlpha';
23 | set(s(i),'UserData', userdata);
24 | end
25 |
--------------------------------------------------------------------------------
/src/svgOffset.m:
--------------------------------------------------------------------------------
1 | function svgOffset(s, source, offset, result)
2 | % Adds a feOffset SVG filter
3 | % PRELIMINARY IMPLEMENTATION (Parameters may change)
4 | %
5 | % svgOffset(s, source, offset, result)
6 | % Parameters:
7 | % s : Array of plot object handles
8 | % source : Any previous defined filter result string, 'SourceGraphic',
9 | % or 'SourceAlpha'.
10 | % offset : Offset value [x y]
11 | % result : String that identifies the filter result for following filter
12 | % stages.
13 | for i = 1:length(s)
14 | userdata = get(s(i),'UserData');
15 | if isfield(userdata, 'svg') && isfield(userdata.svg, 'Filter')
16 | next = length(userdata.svg.Filter) + 1;
17 | else
18 | next = 1;
19 | end
20 | userdata.svg.Filter(next).Subfilter.Type = 'feOffset';
21 | userdata.svg.Filter(next).Subfilter.Source = source;
22 | userdata.svg.Filter(next).Subfilter.Offset = offset;
23 | userdata.svg.Filter(next).Subfilter.Result = result;
24 | set(s(i),'UserData', userdata);
25 | end
26 |
--------------------------------------------------------------------------------
/src/svgSpecularLightingDistant.m:
--------------------------------------------------------------------------------
1 | function svgSpecularLightingDistant(s, source, specularConstant, specularExponent, surfaceScale, azimuth, elevation, result)
2 | % Adds a feSpecularLighting SVG filter with distant light source
3 | % PRELIMINARY IMPLEMENTATION (Parameters may change)
4 | %
5 | % svgSpecularLightingDistant(s, source, specularConstant, specularExponent, surfaceScale, azimuth, elevation, result)
6 | % Parameters:
7 | % s : Array of plot object handles
8 | % source : Any previous defined filter result string, 'SourceGraphic',
9 | % or 'SourceAlpha'.
10 | % specularConstant : Specular constant
11 | % specularExponent : Specular exponent
12 | % surfaceScale : Surface scaling factor
13 | % azimuth : Light azimuth angle [deg], typical 225.
14 | % elevation : Light elevation angle [deg], typical 45.
15 | % result : String that identifies the filter result for following filter
16 | % stages.
17 | for i = 1:length(s)
18 | userdata = get(s(i),'UserData');
19 | if isfield(userdata, 'svg') && isfield(userdata.svg, 'Filter')
20 | next = length(userdata.svg.Filter) + 1;
21 | else
22 | next = 1;
23 | end
24 | userdata.svg.Filter(next).Subfilter.Type = 'feSpecularLighting';
25 | userdata.svg.Filter(next).Subfilter.Source = source;
26 | userdata.svg.Filter(next).Subfilter.Result = result;
27 | userdata.svg.Filter(next).Subfilter.SpecularConstant = specularConstant;
28 | userdata.svg.Filter(next).Subfilter.SpecularExponent = specularExponent;
29 | userdata.svg.Filter(next).Subfilter.SurfaceScale = surfaceScale;
30 | userdata.svg.Filter(next).Subfilter.LightType = 'feDistantLight';
31 | userdata.svg.Filter(next).Subfilter.Azimuth = azimuth;
32 | userdata.svg.Filter(next).Subfilter.Elevation = elevation;
33 | set(s(i),'UserData', userdata);
34 | end
35 |
--------------------------------------------------------------------------------
/src/svgTurbulence.m:
--------------------------------------------------------------------------------
1 | function svgTurbulence(s, frequency, octaves, seed, stitch, type, result)
2 | % Adds a feTurbulence SVG filter
3 | % PRELIMINARY IMPLEMENTATION (Parameters may change)
4 | %
5 | % svgTurbulence(s, frequency, octaves, seed, stitch, type, result)
6 | % Parameters:
7 | % s : Array of plot object handles
8 | % frequency : Base frequency, typical 0.05
9 | % octaves : Octaves, typical 2
10 | % seed : Seed value for random generator, typical 0..255
11 | % stitch : Stitch tiles [stitch, noStitch]
12 | % type : Turbulence type [fractalNoise, turbulence]
13 | % result : String that identifies the filter result for following filter
14 | % stages.
15 | for i = 1:length(s)
16 | userdata = get(s(i),'UserData');
17 | if isfield(userdata, 'svg') && isfield(userdata.svg, 'Filter')
18 | next = length(userdata.svg.Filter) + 1;
19 | else
20 | next = 1;
21 | end
22 | userdata.svg.Filter(next).Subfilter.Type = 'feTurbulence';
23 | userdata.svg.Filter(next).Subfilter.BaseFrequency = frequency;
24 | userdata.svg.Filter(next).Subfilter.NumOctaves = octaves;
25 | userdata.svg.Filter(next).Subfilter.Seed = seed;
26 | userdata.svg.Filter(next).Subfilter.StitchTiles = tiles;
27 | userdata.svg.Filter(next).Subfilter.TurbulenceType = type;
28 | userdata.svg.Filter(next).Subfilter.Result = result;
29 | set(s(i),'UserData', userdata);
30 | end
31 |
--------------------------------------------------------------------------------