Could anyone help me how to save the bar graph in png format.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
jaah navi
am 29 Jul. 2021
Kommentiert: jaah navi
am 29 Jul. 2021
how to save the bar graph generated using
applyhatch(gcf,'|-+.\/')
in png while the command executes.
0 Kommentare
Akzeptierte Antwort
DGM
am 29 Jul. 2021
Bearbeitet: DGM
am 29 Jul. 2021
I'm not sure what you mean by "while the command executes", but...
An example:
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
bar(y)
applyhatch(gcf,'|-/')
print('hatchedplot.png','-dpng')
4 Kommentare
Walter Roberson
am 29 Jul. 2021
The "-d" prefix stands for "driver". -dpng selects the driver named "png", which is responsible for outputting PNG image files.
Weitere Antworten (1)
Walter Roberson
am 29 Jul. 2021
%applyhatch is a File Exchange Contribution. We need to install it to
%generate the graphics to demonstrate the save techniques
tn = tempname();
hatch_zip_file = 'https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/e5432c97-4a80-11e4-9553-005056977bd0/7e9c4240-31dc-444d-962b-4ca9dea813ab/packages/zip/hatchpattern.zip';
hz = tn + ".zip";
urlwrite(hatch_zip_file, hz);
cleanme = onCleanup(@() delete(hz));
hzf = tn + "_folder";
mkdir(hzf)
unzip(hz, hzf);
cleanme2 = onCleanup(@() delete(fullfile(hzf, '*')))
addpath(hzf)
fig = figure('name', 'original figure')
bar(rand(5,20))
applyhatch(fig,'|-+.\/')
fig2 = setdiff(get(0,'children'), fig)
satn = tn+"_saveas.png";
ptn = tn+"_print.png";
extn = tn+"_exportgraphics.png";
saveas(fig2, satn)
print(fig2, ptn)
exportgraphics(fig2, extn)
folder = fileparts(tn);
dir(fullfile(folder, '*.png'))
You can see that all three png files were created.
imshow(extn)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Bar Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!