Saving a 1xn Bar plot as a jpg

9 vues (au cours des 30 derniers jours)
Trigg Allen
Trigg Allen le 30 Oct 2020
Modifié(e) : Ameer Hamza le 30 Oct 2020
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?

Réponses (1)

Ameer Hamza
Ameer Hamza le 30 Oct 2020
Modifié(e) : Ameer Hamza le 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

Catégories

En savoir plus sur Printing and Saving dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by