File Exchange

image thumbnail

Axis XX

version 2.6.0.0 (27.3 KB) by Luke Plausin
Add multiple X or Y axes to plots, rescale data, use any function, add data tips, zoom, flexible.

3 Downloads

Updated 10 Dec 2015

GitHub view license on GitHub

This package will allow you to plot data on multiple X or Y axis. Similar to MATLAB's own plotyy function, but less limiting.
Features:
Create any combination of X or Y axes, plot multiple lines on each X or Y axis
Native argument styles and overloaded plot functions supported e.g:
axisyy(xdata, ydata, 'r-', 'LineWidth', 2, 'MarkerSize', 14);
axisyy(TimeSeriesObject, 'b-', 'LineWidth', 3);
Use any plotting function you specify (plot, line, patch, etc)
Set the limits of every axis independently
Ability to update xdata/ydata directly without thinking about the transformation
Compatible with MATLAB's zoom, pan and data cursor tools
Figure is resizeable and rescales objects around colorbars if they are present
The code has been completely rewritten using an object oriented approach.
Originally inspired by AddAxis 5 by Harry Lee

Check the example.m file for some quick tips.

If you find any bugs or have suggestions please write in the comments box or message me. If the submission was helpful, then please rate it.

Comments and Ratings (23)

Bob photonics

I keep getting this error

Subscripted assignment dimension mismatch.

Error in addaxis/plot (line 65)
obj.h_axis_line(end+1) = set_args.PlotFcn(varargin{:});

Error in axisyy/plot (line 13)
obj = obj.plot@addaxis(varargin{:});

Error in addaxis (line 133)
obj = obj.plot(varargin{:});

Error in axisyy (line 10)
obj = obj@addaxis(varargin{:});

Alex Wyatt

Error using matlab.ui.Figure/addlistener
While adding a PostSet listener, property 'Position' in class 'matlab.ui.Figure' is not defined to be SetObservable.

deco

deco (view profile)

Error using matlab.ui.Figure/addlistener
While adding a PostSet listener, property 'Position' in class 'matlab.ui.Figure' is not defined to be SetObservable.

Error in addaxis (line 147)
obj.l_parent_resize = addlistener(obj.GetParentFig, ...

Error in axisyy (line 10)
obj = obj@addaxis(varargin{:});

Error in example (line 29)
Y2 = axisyy(x, 3*cos(x), 'r-');

Warwick

I'm using 2015b; when I run 'example.m' I get most of the plot but then this error msg.

Error using matlab.ui.Figure/addlistener
While adding a PostSet listener, property 'Position' in class 'matlab.ui.Figure' is not
defined to be SetObservable.

Error in addaxis (line 147)
obj.l_parent_resize = addlistener(obj.GetParentFig, ...

Error in axisyy (line 10)
obj = obj@addaxis(varargin{:});

Error in example (line 29)
Y2 = axisyy(x, 3*cos(x), 'r-');

Luke Plausin

Hi Marc,
It looks like the something has changed in version R2015. That line redraws everything when you resize the parent form. If you comment out line 147 it should work but without dynamic resizing

Marc Passy

Error in example file, running on r2015aSP1:

am I doing something wrong?

Error using matlab.ui.Figure/addlistener
While adding a PostSet listener, property 'Position' in class 'matlab.ui.Figure' is not
defined to be SetObservable.

Error in addaxis (line 147)
obj.l_parent_resize = addlistener(obj.GetParentFig, ...

Error in axisyy (line 10)
obj = obj@addaxis(varargin{:});

Error in example (line 29)
Y2 = axisyy(x, 3*cos(x), 'r-');

Luke Plausin

Hi Lukas,

Unfortunately since the addaxis objects are not embedded in the .fig file when you save it, the objects in the saved figure will not resize automatically when you reopen it. The easiest thing to do would be to re-run the code that generates the plot.

Luke Plausin

Hi Juri,

Could you be a bit more specific? What hasn't displayed properly? A screenshot would be very helpful

Perfect code for plotting :)

How is it possible to save to figure with resize handles?

Juri Marcucci

Juri Marcucci

Hi everyone.

Has anybody ever tried to use addaxis with recessionplot? I have been trying to draw multiple time series with addaxis, but when I run recessionplot at the end, some axes get wiped out.
Beyond this, it is a great code! Thanks so much!

Juri

Luke Plausin

Hello everyone,

I've been putting some time into reworking the old code using an object oriented approach. Functionality has improved, and I have some ideas for further development.

If you have any ideas or requests please post them here.

If you found this submission helpful please rate it.

Thanks
Luke

Luke Plausin

Hello Oliver,

I'm sorry but the package doesn't work with subplot - this is because subplot uses normalized units to rescale the axis, whereas Axis XX rearranges objects in the figure with pixel units. There is no easy work around for this.

If you absolutely need to get two plots of this kind into a single figure, the best way would be to look into using the GUI layout toolbox.

http://www.mathworks.com/matlabcentral/fileexchange/47982-gui-layout-toolbox

I would suggest partitioning the main form with a HBox/VBox or Grid, and then write calls to the addaxis.resizeParentAxis function

Luke Plausin

Hello Sabine,
I'm not familiar with Dynamic Date Ticks - but I've looked through their code. It seems that the dynamicDateTicks function sets the zoom, pan and datatip callbacks on the main axis handle. Axis XX relies on these callbacks to update the axis limits when zooming/paning/data-tipping.

The best work around would be to write your own callback functions which invoke the callbacks for both Dynamic Date Ticks and Axis XX.

Hope that helps

Luke

Sabine Schenk

Great! Thanks a lot!
Has anybody tried to use this function in combination with the Intelligent Dynamic Date Ticks (http://www.mathworks.com/matlabcentral/fileexchange/27075-intelligent-dynamic-date-ticks)?
By using the DynamicDateTick-function the zoom, pan, and data cursor tools don't work anymore. Any idea?
I'm using R2014b.

Olivier

Great job! Thanks a lot :)

This works with R2011a.
The use of subplot isn't compatible with this function, isn't it?
For displaying the good text (label+value) for a curve, which has been plotted with addaxisplot, it seems to be enough to adapt a part of aadDataTipText.m with the following text :

%lines = zeros(size(aad));%OLD
lines = [];%NEW
lax = zeros(size(aad));
for i = 1:length(aad)
haad = aad{i};
lax(i) = haad(1);
%lines(i) = haad(2); %OLD
N=length(haad);%NEW
if N>1%NEW
for j=2:1:N%NEW
lines(j-1,i) = haad(j);%NEW
end%NEW
end%NEW
end

%%
%lineidx] = find(lines == lineH);%OLD
[numplot lineidx] = find(lines == lineH);%NEW

Rahul

Rahul (view profile)

Worked great for me with 2014b after making changes suggested by Danny and Luke

Danny

Danny (view profile)

Same problem here too... but I seem to have had good luck after changing line 12 in aadwindowresizefcn to:
if ~isempty(ax_manage)

(using 2015a)

I also have the same problem as loesch89 and Florian Haase. (using 2015a)

I've the same problem as loesch89.

loesch89

fixed the below error but was met with a new one. tried to fix it with isempty but that lead to more errors.

I was just using the demo m-file, other than the error looks like just what I need.

It might also be worth making the code version dependant or make a 2014b++ version with the changes already in built.

Here is the error, I'm using 2014b:

>> addaxisdatatest
Conversion to logical from matlab.graphics.axis.Axes is not possible.

Error in aadwindowresizefcn (line 12)
if ax_manage

Error in addaxis>@(x,y)aadwindowresizefcn(x,y) (line 204)
set(hfig, 'ResizeFcn', @(x,y) aadwindowresizefcn(x,y));

Error in addaxislabel (line 56)
fcn(hfig, 'addaxislabel');

Error in addaxisdatatest (line 10)
addaxislabel(1,'one');

Luke

Luke (view profile)

Changes in Matlab 2014b require updates to the file aa_splot.m. Change 'colorord' to 'ColorOrder'.

Yangqing

When I run addaxisdatatest with MATLAB 2014b, there is a error as shown below. But there is no such error with MATLAB 2014a.

Error using matlab.graphics.axis.Axes/get
There is no colorord property on the Axes class.
Error in aa_splot (line 13)
cord = get(gca,'colorord');
Error in addaxis (line 130)
hplts = aa_splot(varargin{:});
Error in addaxisdatatest (line 6)
addaxis(x,sin(x-pi/3));

Updates

2.6.0.0

Changed to GPL license. Reverted title back to Axis XX. Support for intermediate AddAxis 6 removed (message me if you need the old code)

2.5.0.0

Moved the code to Github

2.4.0.0

Added compatiability for semilogy semilogx and reverse direction ticks
Added example of subplots (of sorts)
Improved axis scaling - FigureResizeFcn now available to user

2.3.0.0

Updated description

2.3.0.0

Updated file description

2.3.0.0

Additional axis background colours will now dynamically match those of the container.

2.2.0.0

Fixed a minor bug in the zoom routine. Improved figure resizing

2.1.0.0

Fixed an error in the datatips
Fixed an error preventing the figure from resizing after an additional axis is deleted

2.0.0.0

Changed image

2.0.0.0

Complete overhaul of code
New class interface not compatiable with AddAxis6 - old code included for legacy users
You can now plot on any combination of X or Y axis

Known issues -
Not yet compatiable with subplot semilog or loglog

1.3.0.0

Removed redundant .m files from package and updated the readme file. Better datatip text. Updated screenshot

1.2.0.0

Source code mods to fix a couple of bugs

1.1.0.0

Edited description

MATLAB Release Compatibility
Created with R2013b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: addaxis, GUI Layout Toolbox, GUI Layout Toolbox

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor