37
37
% export_fig ... -silent
38
38
% export_fig ... -notify
39
39
% export_fig ... -regexprep <pattern> <replace>
40
+ % export_fig ... -xkcd
40
41
% export_fig ... -toolbar
41
42
% export_fig ... -menubar
42
43
% export_fig ... -contextmenu
103
104
% default name 'export_fig_out' is used. If neither file extension
104
105
% nor a format parameter are specified, a ".png" is added to the
105
106
% filename and the figure saved in PNG format.
107
+ % Special case: if filename has .fig extension the current figure is
108
+ % saved to that file in Matlab FIG format; if no file is open, the
109
+ % specified file is regarded as input file, and used for re-export.
106
110
% -<format> - string(s) containing the output file extension(s). Options:
107
111
% '-pdf','-eps','emf','-svg','-png','-tif','-jpg','-gif' and '-bmp'.
108
112
% Multiple formats can be specified, without restriction.
149
153
% formats or figures with patches and/or transparent annotations;
150
154
% painters for vector formats without patches/transparencies.
151
155
% -<colorspace> - option indicating which colorspace color figures should
152
- % be saved in: RGB (default), CMYK or gray. Usage example: '-gray'.
153
- % Note: CMYK is only supported in PDF, EPS and TIF formats.
156
+ % be saved in: RGB (default), CMYK or gray.
157
+ % Usage example: '-gray' creates a grayscale version of the figure.
158
+ % Note: CMYK is only supported in PDF, EPS and TIF output formats.
154
159
% -q<val> - option to vary bitmap image quality (PDF, EPS, JPG formats only).
155
160
% A larger val, in the range 0-100, produces higher quality and
156
161
% lower compression. val > 100 results in lossless compression.
223
228
% string or array of strings; case-sensitive), with the corresponding
224
229
% <new> string(s), in EPS/PDF files (only). See regexp function's doc.
225
230
% Warning: invalid replacement can make your EPS/PDF file unreadable!
231
+ % -xkcd - renders the axes in XKCD hand-drawn style (see http://xkcd.com)
226
232
% -toolbar - adds an interactive export button to the figure's toolbar
227
233
% -menubar - adds an interactive export menu to the figure's menubar
228
234
% -contextmenu - adds interactive export menu to figure context-menu (right-click)
392
398
% 07/12/23: (3.43) Fixed unintended modification of colorbar in bitmap export (issue #385)
393
399
% 21/02/24: (3.44) Fixed: text objects with normalized units were not exported in some cases (issue #373); added check for invalid ghostscript installation (issue #365)
394
400
% 02/05/24: (3.45) Display the builtin error message when uifigure cannot be exported (issue #387); fixed contour labels with non-default FontName incorrectly exported as Courier (issue #388)
401
+ % 09/05/24: (3.46) Added -xkcd option (thanks @slayton); added .fig input and output format (previously undocumented & buggy); redirect .tex output to matlab2tikz utility
395
402
%}
396
403
397
404
if nargout
429
436
[fig , options ] = parse_args(nargout , fig , argNames , varargin{: });
430
437
431
438
% Check for newer version and exportgraphics/copygraphics compatibility
432
- currentVersion = 3.45 ;
439
+ currentVersion = 3.46 ;
433
440
if options .version % export_fig's version requested - return it and bail out
434
441
imageData = currentVersion ;
435
442
return
674
681
try
675
682
oldWarn = warning ;
676
683
684
+ % If XKCD option was specified, render figure as XKCD before any export
685
+ if options .xkcd
686
+ xkcd_axes = xkcdify(fig );
687
+ end
688
+
677
689
% Export bitmap formats first
678
690
if isbitmap(options )
679
691
if abs(options .bb_padding ) > 1
1516
1528
end
1517
1529
end
1518
1530
1531
+ % Revert any XKCD rendering
1532
+ try delete(xkcd_axes ); catch , end
1533
+
1519
1534
% Notify user by popup, if -notify option was specified
1520
1535
if options .notify && exported_files > 0
1521
1536
% TODO don't notify when exporting to file just for clipboard output
1551
1566
% Revert figure properties in case they were changed
1552
1567
try set(fig ,' Units' ,oldFigUnits , ' Position' ,pos , ' Color' ,tcol_orig ); catch , end
1553
1568
try set(textn , ' Units' ,' normalized' ); catch , end
1569
+ % Revert any XKCD rendering
1570
+ try delete(xkcd_axes ); catch , end
1554
1571
% Display possible workarounds before the error message
1555
1572
if ~isempty(regexpi(err .message ,' setopacityalpha' )) % #ok<RGXPI>
1556
1573
% Alert the user that transparency is not supported (issue #285)
@@ -1710,6 +1727,7 @@ function notify(filename)
1710
1727
' preserve_size' , false , ...
1711
1728
' silent' , false , ...
1712
1729
' notify' , false , ...
1730
+ ' xkcd' , false , ...
1713
1731
' regexprep' , [], ...
1714
1732
' toolbar' , false , ...
1715
1733
' menubar' , false , ...
@@ -1735,6 +1753,7 @@ function notify(filename)
1735
1753
options.alpha = (nout == 2 ); % user requested alpha output
1736
1754
options.handleName = ' ' ; % default handle name
1737
1755
wasOutputRequested = false ;
1756
+ saveFig = false ;
1738
1757
1739
1758
% Go through the other arguments
1740
1759
skipNext = 0 ;
@@ -1804,6 +1823,12 @@ function notify(filename)
1804
1823
options.gif = true ;
1805
1824
addToOptionsStr = false ;
1806
1825
wasOutputRequested = true ;
1826
+ case ' tex'
1827
+ url = hyperlink(' https://github.com/matlab2tikz/matlab2tikz' ,' matlab2tikz' );
1828
+ error(' export_fig:TEX' ,' export_fig does not support tex output. Use the %s utility for this.' , url );
1829
+ case ' fig'
1830
+ saveFig = true ;
1831
+ addToOptionsStr = false ;
1807
1832
case ' rgb'
1808
1833
options.colourspace = 0 ;
1809
1834
case ' cmyk'
@@ -1882,6 +1907,9 @@ function notify(filename)
1882
1907
case ' regexprep'
1883
1908
options.regexprep = varargin(a + 1 : a + 2 );
1884
1909
skipNext = 2 ;
1910
+ case ' xkcd'
1911
+ options.xkcd = true ;
1912
+ addToOptionsStr = false ;
1885
1913
case ' toolbar'
1886
1914
options.toolbar = true ;
1887
1915
addToOptionsStr = false ;
@@ -2044,7 +2072,7 @@ function notify(filename)
2044
2072
case {' tif' , ' tiff' ,' jpg' , ' jpeg' ,' png' ,' bmp' ,' eps' ,' emf' ,' pdf' ,' svg' ,' gif' }
2045
2073
options = setOptionsFormat(options , ext );
2046
2074
wasOutputRequested = true ;
2047
- case ' . fig'
2075
+ case ' fig'
2048
2076
% If no open figure, then load the specified .fig file and continue
2049
2077
figFilename = thisArg ;
2050
2078
if isempty(fig )
@@ -2054,10 +2082,14 @@ function notify(filename)
2054
2082
options.handleName = [' openfig('' ' figFilename ' '' )' ];
2055
2083
else
2056
2084
% save the current figure as the specified .fig file and exit
2057
- saveas(fig(1 ),figFilename );
2085
+ hFig = ancestor(fig(1 ), ' figure' );
2086
+ saveas(hFig ,figFilename );
2058
2087
fig = - 1 ;
2059
2088
return
2060
2089
end
2090
+ case ' tex'
2091
+ url = hyperlink(' https://github.com/matlab2tikz/matlab2tikz' ,' matlab2tikz' );
2092
+ error(' export_fig:TEX' ,' export_fig does not support tex output. Use the %s utility for this.' , url );
2061
2093
otherwise
2062
2094
options.name = thisArg ;
2063
2095
wasOutputRequested = true ;
@@ -2116,6 +2148,17 @@ function notify(filename)
2116
2148
options.name = fullfile(char(java .lang .System .getProperty(' user.home' )), options .name(2 : end ));
2117
2149
end
2118
2150
2151
+ % Export the current figure without any manipulation, if requested
2152
+ if saveFig
2153
+ if ~isempty(options .name )
2154
+ [fpath ,fname ,~ ] = fileparts(options .name );
2155
+ filename = fullfile(fpath ,[fname ' .fig' ]);
2156
+ else
2157
+ filename = ' output.fig' ;
2158
+ end
2159
+ saveas(ancestor(fig(1 ),' figure' ), filename );
2160
+ end
2161
+
2119
2162
% Compute the magnification and resolution
2120
2163
if isempty(options .magnify )
2121
2164
if isempty(options .resolution )
0 commit comments