Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot outside axis in Matlab

How to plot something outside the axis with MATLAB? I had like to plot something similar to this figure;

Plot with bar outside axis

Thank you.

like image 777
ths1104 Avatar asked Aug 06 '11 02:08

ths1104


Video Answer


1 Answers

Here is one possible trick by using two axes:

%# plot data as usual
x = randn(1000,1);
[count bin] = hist(x,50);
figure, bar(bin,count,'hist')
hAx1 = gca;

%# create a second axis as copy of first (without its content), 
%# reduce its size, and set limits accordingly
hAx2 = copyobj(hAx1,gcf);
set(hAx2, 'Position',get(hAx1,'Position').*[1 1 1 0.9], ...
    'XLimMode','manual', 'YLimMode','manual', ...
    'YLim',get(hAx1,'YLim').*[1 0.9])
delete(get(hAx2,'Children'))

%# hide first axis, and adjust Z-order
axis(hAx1,'off')
uistack(hAx1,'top')

%# add title and labels
title(hAx2,'Title')
xlabel(hAx2, 'Frequency'), ylabel(hAx2, 'Mag')

and here is the plot before and after:

before_screenshotafter_screenshot

like image 69
Amro Avatar answered Sep 27 '22 22:09

Amro