how to save a graph in jpg or any other image format

362 ビュー (過去 30 日間)
Krishnendu Mukherjee
Krishnendu Mukherjee 2012 年 3 月 12 日
回答済み: Toshia M 2023 年 3 月 17 日
how to save a graph in jpg or any other image format

採用された回答

Thomas
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
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
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
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).

Toshia M
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

Image Analyst
Image Analyst 2012 年 3 月 12 日

カテゴリ

Help Center および File ExchangeGraphics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by