how to save a graph in jpg or any other image format
232 次查看(过去 30 天)
显示 更早的评论
how to save a graph in jpg or any other image format
0 个评论
采纳的回答
Thomas
2012-3-12
You can do it programatically as:
figure1 = figure;
axes1 = axes('Parent',figure1)
hold(axes1,'all');
plot(plot what you want to plot)
saveas(figure1,'finename.ext') % here you save the figure
4 个评论
Pratik Nikam
2020-8-10
编辑:Walter Roberson
2020-8-10
I have plotted a curve fitted line of a curve in a graph. Now I wish to measure its angle with X axis. that's why I need a graph to be saved as an image, so that I could apply a formula and get its angle without manual interference. I use 2018a version, but the code you suggested doesn't seem working for it. Can you please help?
Here is a part of the code:
%r1 & c1 are taken from the image for the curvefitting.
%max(r1)= highest value of r1 & min(r1)= minimum value of r1
coefficients = polyfit(r1, c1, 3);
fittedA = linspace(min(r1), max(r1), 500);
fittedB = polyval(coefficients, fittedA);
plot(fittedA, fittedB, 'b-', 'linewidth', 1);
set(gca, 'YDir', 'reverse'); %mirroring the plot
Walter Roberson
2020-8-10
I do not understand why you think that applying a formula to an image showing a graph is going to get you a useful result.
figure1 = figure;
axes1 = axes('Parent',figure1)
%r1 & c1 are taken from the image for the curvefitting.
%max(r1)= highest value of r1 & min(r1)= minimum value of r1
coefficients = polyfit(r1, c1, 3);
fittedA = linspace(min(r1), max(r1), 500);
fittedB = polyval(coefficients, fittedA);
plot(axes1, fittedA, fittedB, 'b-', 'linewidth', 1);
set(axes1, 'YDir', 'reverse'); %mirroring the plot
saveas(figure1, 'YourFileNname.png')
But this would get you an image of a plot complete with tick marks and tick labels and lots of whitespace. It is going to be a nuisance to process the image to get anything useful out of it. It would make a lot more sense to just process the fittedA and fittedB data directly.
更多回答(3 个)
Jacob Halbrooks
2012-3-12
From your figure, select File->Save as and choose a file type in the dialog. If you need to save your figure programmatically, the PRINT command has options to choose a file type (such as the -djpeg flag for JPG format).
0 个评论
Toshia M
2023-3-17
Starting in R2020a, you can use the exportgraphics function to save the contents of any axes, figure, tiled chart layout, or panel within a figure. This function allows you to save an image such as a JPEG, TIFF, or PNG. You can also save the content as vector graphics in a PDF file. For example, create a plot and save it as a JPEG. Then save it as vector graphics in a PDF file.
plot([0 4 2 6 3])
ax = gca;
exportgraphics(ax,"myplot.jpg") % Save a JPEG
exportgraphics(ax,"myplot.pdf","ContentType","vector") % Save a PDF
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!