Borrar filtros
Borrar filtros

How to save good quality plots in Matlab using code?

3 visualizaciones (últimos 30 días)
Hi Everyone. I have done few spatial plots in matlab. But, I am facing problem while saving the plots using code. However, during manually saving plots I do not have any problems. For few plots it is fine to save manually, but for large number of plots it is difficult to save one by one plot manually. I am attaching two files along with this question, one of then is saved by code and another is saved manually.
test_1.jpg: It is saved manually
test_2.jpg: It is saved using code
I plotted and saved the code using the following code. In test_1.jpg the plot is showing quite good (it is saved manually by maximize the plotting window), but test_2.jpg is not that good. Please show me some light on this issue. I hope my issue is clear, please let me know if you have any doubt. Thanks in advance. Also, if anyone can tell how to generate good quality plots, for publication/posters that will be really helpful.
for i = 1:1
figure
pcolor(lon, lat, net_all_sky(:, :, i)')
shading interp
colormap("jet")
colorbar
hold on
plot(coastlon, coastlat, "Color", 'k', "LineWidth", 1.5)
plot(coastlon+360, coastlat, "Color", 'k', "LineWidth", 1.5)
grid on
set(gca,'layer','top')
ax = gca;
ax.GridLineWidth = 1.5;
ax.GridAlpha = 0.4;
c = colorbar;
clim([-200 170])
ylabel(c, "TOA short wave flux in Wm^{-2}", "FontSize", 15, "FontWeight", "bold")
title(months(i))
exportgraphics(ax, "test_2.jpg", "Resolution", 300)
end

Respuesta aceptada

Venkat Siddarth Reddy
Venkat Siddarth Reddy el 13 de En. de 2024
Editada: Venkat Siddarth Reddy el 13 de En. de 2024
I understand that the you trying to automate the process of saving a plot, but you are facing an issue with the quality of the image generated.
After comparing the manually generated image with the image generated by the script, I noticed that the manually created image displays the plot in a maximized window format, as you provided. However, the image generated by the script appears in a compact format.
To maximize the window of the plot before saving it , you can set the "WindowState" property of the "figure" to "maximized" and then export the plot:
figure('WindowState','maximized')
To learn more about "WindowState" and other properties of "figure", please refer to the documentation: https://www.mathworks.com/help/matlab/ref/matlab.ui.figure-properties.html
If this approach doesn't generate an image of your desired quality, I would recommend increasing the "Resolution" of the image being exported after maximizing the plot window.
I hope this helps!

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by