Rescaling and extending the axes of compass plots

16 views (last 30 days)
Using 2014b.
I have multiple compass plots on the same figure, and I want to set them all to the same scale. When I try to set the axis limits of all the plots to those of the largest one, the smaller plots rescale so that the arrows are the right size. However, each entire plot itself simply shrinks. It does not extend the axes out to the specified limit or redraw the tick marks. How do I get it to keep the same size while rescaling the arrows and tick marks inside of it? The code I have goes as follows:
%make dummy data as described in the compass plot documentation
rng(0,'twister')
M = randn(20,20);
small_data = eig(M);
large_data = 2*small_data;
ax = zeros(2,2,2);%holds the axis limits for the 2 plots
figure
subplot(1,2,1)
compass(large_data)%draw the plot with larger arrows
curr_axis = gca;
ax(1,:,:) = [curr_axis.XLim; curr_axis.YLim];%pull out the axis limits for later comparing
subplot(1,2,2)
compass(small_data)%draw the plot with smaller arrows
curr_axis = gca;
ax(2,:,:) = [curr_axis.XLim; curr_axis.YLim];%pull out the axis limits for later comparing
%go back to the each plot and set their limits to the larger of the pair.
subplot(1,2,1)
curr_axis = gca;
curr_axis.XLim = [min(ax(:,1,1)) max(ax(:,1,2))];
curr_axis.YLim = [min(ax(:,2,1)) max(ax(:,2,2))];
subplot(1,2,2)
curr_axis = gca;
curr_axis.XLim = [min(ax(:,1,1)) max(ax(:,1,2))];
curr_axis.YLim = [min(ax(:,2,1)) max(ax(:,2,2))];
  1 Comment
Lawrence
Lawrence on 5 May 2015
I wonder if there is a bug in the plot drawing. If I watch the axis properties in Inspector as I change XLim and YLim, the XTick and YTick variables adjust automatically to what they should be, but the ticks don't update on the figure itself. It doesn't appear to be a bug with the plot re-drawing, since saving the figure in a .fig file and loading it doesn't fix the issue. Neither does changing the Figure.Renderer or Axes.XTick and Axes.YTick properties.

Sign in to comment.

Answers (2)

Lawrence
Lawrence on 8 May 2015
So I have a workaround which entails pre-drawing each compass plot. I use an invisible arrow the size of the maximum arrow I anticipate from the data.
%make dummy data as described in the compass plot documentation
rng(0,'twister')
M = randn(20,20);
small_data = eig(M);
large_data = 2*small_data;
%find the largest magnitude in all the data
total_data = [small_data; large_data];
magnitude = (real(total_data).^2 + imag(total_data).^2).^.5;
max_magnitude = max(magnitude);
figure
subplot(1,2,1)
hidden_arrow = compass(max_magnitude,0);%I don't care the direction
hidden_arrow.Color = 'none';
hold on
compass(large_data)%draw the plot with larger arrows
hold off
subplot(1,2,2)
hidden_arrow = compass(max_magnitude,0);%I don't care the direction
hidden_arrow.Color = 'none';
hold on
compass(small_data)%draw the plot with smaller arrows
hold off

Vinod Sudheesh
Vinod Sudheesh on 27 May 2015
Hi Lawrence,
You could have both the "compass graphs" to be of same size by having the "axes" that contains these "compass graphs" to be of the same size. Note that the "compass" function re-sizes each of the "axes" while being invoked. You could consider the approach below to mitigate this
rng(0,'twister');
M = randn(20,20);
small_data = eig(M);
large_data = 2*small_data;
ax = zeros(2,2,2);
figure
subplot(1,2,1)
tmp=get(gca,'position');
compass(large_data);
set(gca,'position',tmp);
subplot(1,2,2)
tmp=get(gca,'position');
compass(small_data);
set(gca,'position',tmp);
Hope this helps !
Vinod

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!