Two plots per axis using addaxis

19 views (last 30 days)
Aya on 7 Sep 2014
Commented: Aya on 7 Sep 2014
Dear Matlab users,
I have three variables I want to plot in one figure (temperature, salinity, chlorophyll). The data is split into two variables "plume" and "P7_3m". They are both 8X5 matrices with column vectors,
[date salinity temperature attenuation chlorophyll].
The problem is I want to plot two lines (one solid, another dashed) of the same color for each of the three variables to compare among plume vs P7_3m. The x-axis is "xt" and labeled with "months". Below is the code I have and does not work because after the use of ADDAXIS, the axes handle goes back to the original first plot axis. Is there a way to access the axis plotted by ADDAXIS? So I can plot my dashed line on the same axis as the solid line created by ADDAXIS?
I'd appreciate your help and time. Thank you in advance!
figure; hold on % start making the figure
ss=20; % setting up the plot
set(0,'DefaultAxesFontSize', ss)
months={'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug'}; % x axis
set(gca,'xticklabel',months, 'fontsize', ss)
plot(xt,plume(:,2),'b') % plot first plot, salinity
haxes1 = gca;
addaxis(xt,plume(:,5),[0 12],'color',[0 0.5 0])
plot(xt,P7_3m(:,5),'color',[0 0.5 0])
ylabel('Practical Salinity')
addaxislabel(2,'Potential Temperature (^{\circ}C)')
addaxislabel(3, 'Chlorophyll a Fluorescence (ug/l)')

Answers (1)

Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh on 7 Sep 2014
Hi Aya,
use hold on after you crate your axis not after figure
hold on works on axis, look at the MATLAB documentation.
doc hold
You used hold on before defining or creating an axis, I don't think it that would do anything at all. Move hold on to the next line after the first plot command, plot command automatically creates an axis if one doesn't exist, and hold on will effect the existing axis created by plot.
I had a look at your code and it should be ok I guess.
I never happened to use addaxis though, I don't know what's that, probably a code developed by someone and not MATHWORKS. I believe the only reason you're using addaxis is that simple problem you made(placing hold on before plot)
You're not into doing something complicated and I'm sure you can do it needless of addaxis.
Good Luck!
  1 Comment
Aya on 7 Sep 2014
Hello Salaheddin,
Thank you very much for your reply! I took your advice and moved the hold on to after I plotted my first line
plot(xt,plume(:,2,'b'); hold on
But I still get the same plot (attached below) that plots the other two dashed lines on the same axis as the first (values are lower than first axis Ylim so not showing up in this figure).
Will you be able to give me advice on making the plot without using the ADDAXIS m file,
Thank you again,

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!