How to save the plot in bitmap format with resolution 1200dpi?

2 views (last 30 days)
I want to save the plot in the bitmap with resolution 1200dpi in MATLab. I tried but not succeeded. The program is below:
plot(x,y6);set(gca,'FontSize',12,'FontWeight','bold','LineWidth',2)
xlim([1 372])
ylabel('Temperature (deg.Cel.)','FontWeight','bold','FontSize',12)
xlabel('Months','FontWeight','bold','FontSize',12)
hold on
m1=plot(xjan,y6,'*','MarkerSize', 6,'MarkerFaceColor','black','MarkerEdgeColor', 'black');set(gca,'FontSize',12,'FontWeight','bold','LineWidth',2)
xlim([1 372])
ylabel('Temperature (deg.Cel.)','FontWeight','bold','FontSize',12)
xlabel('Months','FontWeight','bold','FontSize',12)
hold on
m2=plot(xjun,y6,'ro','MarkerSize', 4,'MarkerFaceColor','red','MarkerEdgeColor', 'red');set(gca,'FontSize',12,'FontWeight','bold','LineWidth',2)
xlim([1 372])
ylabel('Temperature (deg.Cel.)','FontWeight','bold','FontSize',12)
xlabel('Months','FontWeight','bold','FontSize',12)% hold on
leg = legend([m1 m2],{'May','August'});
title('500hPa','FontWeight','bold','FontSize',14)
%saveas(gcf,'-dpng','-r300','test.png')
print (gcf, '-dbmp','-r1200', 'myfile.bmp')
Kindly, guide me regarding this.
Thanks & Regards

Answers (1)

Shubham
Shubham on 2 Sep 2024
Hi Gargi,
To save a plot in MATLAB as a bitmap image with a specific resolution, such as 1200 DPI, you can use the print function with the appropriate options. It looks like you are almost there, but there might be a small issue with the syntax or the order of arguments. Here’s how you can correctly save your plot with the desired resolution:
% Your plotting code
plot(x, y6);
set(gca, 'FontSize', 12, 'FontWeight', 'bold', 'LineWidth', 2);
xlim([1 372]);
ylabel('Temperature (deg.Cel.)', 'FontWeight', 'bold', 'FontSize', 12);
xlabel('Months', 'FontWeight', 'bold', 'FontSize', 12);
hold on;
m1 = plot(xjan, y6, '*', 'MarkerSize', 6, 'MarkerFaceColor', 'black', 'MarkerEdgeColor', 'black');
set(gca, 'FontSize', 12, 'FontWeight', 'bold', 'LineWidth', 2);
xlim([1 372]);
ylabel('Temperature (deg.Cel.)', 'FontWeight', 'bold', 'FontSize', 12);
xlabel('Months', 'FontWeight', 'bold', 'FontSize', 12);
hold on;
m2 = plot(xjun, y6, 'ro', 'MarkerSize', 4, 'MarkerFaceColor', 'red', 'MarkerEdgeColor', 'red');
set(gca, 'FontSize', 12, 'FontWeight', 'bold', 'LineWidth', 2);
xlim([1 372]);
ylabel('Temperature (deg.Cel.)', 'FontWeight', 'bold', 'FontSize', 12);
xlabel('Months', 'FontWeight', 'bold', 'FontSize', 12);
% Legend and title
leg = legend([m1 m2], {'May', 'August'});
title('500hPa', 'FontWeight', 'bold', 'FontSize', 14);
% Save the plot as a bitmap image with 1200 DPI
print(gcf, 'myfile.bmp', '-dbmp', '-r1200');
Key Points:
  • Order of Arguments: In the print function, the filename ('myfile.bmp') should come before the format ('-dbmp') and resolution ('-r1200').
  • Resolution: The -r1200 option specifies the resolution in dots per inch (DPI).
  • Format: The -dbmp option specifies that the output format is a bitmap.
Additional Tips:
  • Figure Size: Ensure that your figure is of an appropriate size before saving, as the DPI setting will scale the figure to that resolution. You can adjust the figure size using set(gcf, 'Position', [left, bottom, width, height]).
  • Check Output: After running the script, check the saved file to ensure it meets your quality and resolution expectations.
  • Alternative Formats: If you encounter issues with bitmap, consider using other formats like PNG (-dpng) or TIFF (-dtiff) which also support high resolutions.

Tags

Community Treasure Hunt

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

Start Hunting!