Saving a 1xn Bar plot as a jpg
3 views (last 30 days)
Show older comments
Hello,
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
test = bar(y)

I want to save this bar plot as an image programatically. I have no issues saving a 1x1 Bar using saveas(), but when I have a 1xN Bar then I get this errorr:
Error using checkArgsForHandleToPrint
Can print only one page at a time.
Error in checkArgsForHandleToPrint
Error in print>LocalCreatePrintJob (line 101)
handles = checkArgsForHandleToPrint(0, varargin{:});
Error in print (line 38)
[pj, inputargs] = LocalCreatePrintJob(varargin{:});
Error in saveas (line 181)
print( h, name, ['-d' dev{i}] )
How can I programatically save a 1xN bar plot?
0 Comments
Answers (1)
Ameer Hamza
on 30 Oct 2020
Edited: Ameer Hamza
on 30 Oct 2020
saveas() is quite an old function and not suitable for getting high-quality images. If you are using a recent version of MATLAB, then try exportgraphics()
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
bar(y)
exportgraphics(gcf, 'filename.jpg', 'Resolution', 300)
If you are using an older version which does not have exportgraphice() then use this FEX package: https://www.mathworks.com/matlabcentral/fileexchange/23629-export_fig
0 Comments
See Also
Categories
Find more on Printing and Saving in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!