Keeping Markers and Lines from scaling with Paper's size and position?

2 views (last 30 days)
The code at the bottom demonstrates the issue. I am trying to render two (or more) figures in a single-shot by plotting them together using subplot, while ensuring that each individual sub-plot has the same resolution.
The Strategy: 1) Choose the basic picture size (in pixels), 2) Create the figure, 3) Perform a calibration between pixels and centimeters, 4) set the PaperPosition to the desired size - for two subplots I am setting the height of the PaperPosition to be double the height of the basic picture size, and for a case of four subplots I am setting the PaperPosition to be four times the height of the basic picture size. (to maintain resolution per subplot) 5) create the subplot 6) render the figure using cdata = print('-RGBImage','-r0') 7) Partition the matrix to rows accordingly and save it as an image using imwrite.
It's important to mention, that this issue doesn't exist in low res figures, rather it occurs when you try to create a hi-res image (which exceeds the monitors/display resolution).
function [ ] = MarkerScalingExample( )
clc;
singlePicSize_PX = [1000 1000]; % W x H
for NumOfPlots = [2 4]
close all;
hF_S = figure('Visible','off','PaperPositionMode','manual','PaperUnits','centimeters');
hF_S.Units = 'pixel';
hF_S.Position = [0 0 singlePicSize_PX];
hF_S.Units = 'centimeters';
singlePicSize_CM = hF_S.Position(3:4);
hF_S.PaperPosition = [0 0 ...
singlePicSize_CM(1)...
singlePicSize_CM(2)*NumOfPlots];
ax_S = subplot(NumOfPlots,1,2,'Parent',hF_S);
framePos = [0 (NumOfPlots-2)/NumOfPlots 1 1/NumOfPlots];
ax_S.Position = [0.1 (framePos(2) + framePos(4)*0.1) 0.8 framePos(4)*0.8];
plot(1,1,'d','MarkerFaceColor','b');
cdata = print('-RGBImage','-r0');
size(cdata)
if NumOfPlots == 2
imwrite(cdata(singlePicSize_PX(2)+1:2*singlePicSize_PX(2),:,:),'test_Size2_of_2.png');
else
imwrite(cdata(singlePicSize_PX(2)+1:2*singlePicSize_PX(2),:,:),'test_Size2_of_4.png');
end
end
end

Answers (0)

Categories

Find more on Visual Exploration in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!