Finding the width and height of white part of plot (not figure) in pixels

2 views (last 30 days)
Hello all,
I want to find the pixels that the white part of the plot occupies. I found this but this can not be right (based on my understanding) becasue when i get the width and height (the 3rd and 4th indices of pos1)
y = [0 0 1 3 2 3];
x = [0 1 2 3 4 4]*10.^4;
figure
scatter(x, y, [], 'b*')
axis square % the pixels should be equal becasue of this
h =gcf;
axesHandles = findall(h,'type','axes');
pos1 = get(axesHandles,'position')
and multiply them by the total figure pixels
h.Units = 'pixels'
pos5 = h.Position;
pos5(3) = pos5(3).*pos1(3) ;% multiply the figure x pixels by the normalized occupancy of the
%x plot in the figure
pos5(4) = pos5(4).* pos1(4) % the pixels should be equal here too and they are not
they are not equal and 'axis square' makes them equal in pixels by definition. I have also tried the below to no avail.
axesHandles = findall(h,'type','axes');
pos1 = get(axesHandles,'position')
% 2 3 and 4 are incorrect because the pixels should equal eachother
pos2 = getpixelposition(gcf)
pos3 = getpixelposition(axesHandles)
pos4 = getpixelposition(gca)
%%
h.Units = 'pixels'
pos5 = h.Position;
pos5(3) = pos5(3).*pos1(3) ;% multiply the figure x pixels by the normalized occupancy of the
%x plot in the figure
pos5(4) = pos5(4).* pos1(4) % the pixels should be equal here too and they are not
I need to know the pixel position of the white plot becasue I want to be able to interpolate where each value is a set numbver of pixels apart. I need it to make a nice figure in illustrator. It would be really difficult to go into detail about why I need it but I really don't want to go down that rabbit hole.
futhermore I find the following peculiar and was wondering how this is explained.
y = [0 0 1 3 2 3];
x = [0 1 2 3 4 4]*10.^4;
figure
scatter(x, y, [], 'b*')
axis square % the pixels should be equal becasue of this
h =gcf;
now I stretch the figure so that it is very tall (height>>width)
h =gcf;
axesHandles = findall(h,'type','axes');
pos1 = get(axesHandles,'position')
pos1 =
0.1300 0.1100 0.7750 0.8150
now stretch it so that it is very wide (width>>height)
h =gcf;
axesHandles = findall(h,'type','axes');
pos1 = get(axesHandles,'position')
pos1 =
0.1300 0.6322 0.7750 0.2394
the distance of the white plot relitive to the figure changes a lot becasue of axis square, pos1(1) is a the same, same thing with pos1(3), it is the same I am so confused. I have referenced this but am still confused!!
Please help, thank you so much!

Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!