Borrar filtros
Borrar filtros

MATLAB plots problem: plot out of axes bounds on rotation

2 visualizaciones (últimos 30 días)
Brian
Brian el 8 de Jul. de 2016
Editada: Brian el 8 de Jul. de 2016
Hello, thanks for looking at this, I have a problem with a plot I have in MATLAB: basically, the plot goes out of the bounds of the parent axes.
I have two pictures attached: one of the GUIDE app and another of it deployed. In both, the axes position does not change, however, every time I make a plot in the contained axes I get this resizing of the plot.
And here is the code I use to plot various data in the axes:
%%Bounding box
% Bounding box will contain a patch shell of the geometric domain, and 3
% plot3 lines of the current curSlice to help with the orientation.
% Make a bounding box of the data
boxDim = ...
[0 0 0; max(axhorz) 0 0; 0 max(axvert) 0; max(axhorz) max(axvert) 0; 0 0 max(saghorz); max(axhorz) max(saghorz); 0 max(axvert) max(saghorz); max(axhorz) max(axvert) max(saghorz)];
faceMx = [1 2 4 3; 5 6 8 7; 1 2 6 5; 1 3 7 5; 2 4 8 6; 3 4 8 7];
set(handles.unified_ui, 'CurrentAxes', handles.trac_3dAxes)
patch('Vertices', boxDim, 'Faces', faceMx, 'FaceColor', 'g', 'FaceAlpha', 0.05, 'EdgeColor', 'b');
% Now, set up current slice lines
axial_line = [curSlice(1) curSlice(2) 0; ...
curSlice(1) curSlice(2) max(saghorz)];
sagittal_line = [curSlice(1) 0 curSlice(3); ...
curSlice(1) max(axvert) curSlice(3)];
coronal_line = [0 curSlice(2) curSlice(3); ...
max(axhorz) curSlice(2) curSlice(3)];
% Plot current slice lines
handles.plots.trac_3dSliceBounds.axial_line = plot3([axial_line(1,1) axial_line(2,1)], ...
[axial_line(1,2) axial_line(2,2)], ...
[axial_line(1,3) axial_line(2,3)], 'r--');
handles.plots.trac_3dSliceBounds.sagittal_line = plot3([sagittal_line(1,1) sagittal_line(2,1)], ...
[sagittal_line(1,2) sagittal_line(2,2)], ...
[sagittal_line(1,3) sagittal_line(2,3)], 'r--');
handles.plots.trac_3dSliceBounds.coronal_line = plot3([coronal_line(1,1) coronal_line(2,1)], ...
[coronal_line(1,2) coronal_line(2,2)], ...
[coronal_line(1,3) coronal_line(2,3)], 'r--');
% Last, create arrows specifying x,y,z coord system
air_width = 3;
arrow3(boxDim(1,:), boxDim(2,:), 'e', ar_width, ar_width);
arrow3(boxDim(1,:), boxDim(3,:), 'e', ar_width, ar_width);
arrow3(boxDim(1,:), boxDim(5,:), 'e', ar_width, ar_width);
text(mean(boxDim(1:2,1)), mean(boxDim(1:2,2)), mean(boxDim(1:2,3)), ' X', 'Color', 'w');
text(mean([boxDim(1,1) boxDim(3,1)]), mean([boxDim(1,2) boxDim(3,2)]), mean([boxDim(1,3) boxDim(3,3)]), ' Y', 'Color', 'w');
text(mean([boxDim(1,1) boxDim(5,1)]), mean([boxDim(1,2) boxDim(5,2)]), mean([boxDim(1,3) boxDim(5,3)]), ' Z', 'Color', 'w');
% Axis resizing, equal and view setting
x_Range = range(boxDim(:,1)); y_Range = range(boxDim(:,2)); z_Range = range(boxDim(:,3));
range_fac = 3;
new_xmin = min(boxDim(:,1)) - x_Range/range_fac; new_xmax = max(boxDim(:,1)) + x_Range/range_fac;
new_ymin = min(boxDim(:,2)) - y_Range/range_fac; new_ymax = max(boxDim(:,2)) + y_Range/range_fac;
new_zmin = min(boxDim(:,3)) - z_Range/range_fac; new_zmax = max(boxDim(:,3)) + z_Range/range_fac;
axis(handles.trac_3dAxes, [new_xmin new_xmax new_ymin new_ymax new_zmin new_zmax]);
axis(handles.trac_3dAxes, 'equal');
Any ideas on why I'm getting this problem? Thanks!
EDIT: I think I know the problem, but I will keep this open because I don't know how (or why) this happens.
The outer position property changes while I'm plotting for some reason to something outside the geometric bounds of the axes. By using the command:
set(handles.trac_3dAxes, 'OuterPosition', get(handles.trac_3dAxes, 'Position'))
I was able to resize it back properly so it fit in the original space I had for it.
Using the command
set(handles.trac_3dAxes, 'ActivePositionProperty', 'Position');
had no effect.

Respuestas (0)

Categorías

Más información sobre Graphics Object Properties en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by