You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to create a graph with 3 y axis
34 views (last 30 days)
Show older comments
Hello,
I been trying to create a graph with 3 y axis and centralise the zero in the middel.
figure
yyaxis left
quiver(EC_time', zeros(size(x_velocity)),x_velocity,y_velocity);
ylim([-0.05 0.05])
axis equal
datetick('x')
axis equal
yyaxis right
bar(EC_time, Mayflux);
ylim([-40 40]);
axis equal
hold on
plot(EC_time, oxygen_may1, 'o-');
hold all
plot(EC_time, oxygen_may1, 'ro-');
plot(EC_time, oxygen_may_optode1, 'go-');
ylim([245 248]);
Could some one give me advise on this? I was trying addaxis but it was not working.
figure
plot(advN.harmonic_fit.thf, Umagadvh)
addaxis(EC_time, Mayflux)
% hold on
addaxis(advN.harmonic_fit.thf, udiradvh);
addaxis(EC_time, oxygen_may1, 'ro-')
datetick 'x'
Thank you.
14 Comments
Rebecca Ellis
on 27 Jan 2019
Edited: Rebecca Ellis
on 27 Jan 2019
I would like mulitple y axis and with addaxis I struggel to use quiver or ylim with this function. yyaxis allows for more editing.
The yyaxis with a third y axis with the oxygen_may1
dpb
on 27 Jan 2019
Edited: dpb
on 27 Jan 2019
K>> which addaxis
'addaxis' not found.
K>>
?? is addaxis??
You can do whatever you want with any axis handle from position to whatever...it matters not how it was actually created.
As an aside not terribly related to the number/placement of axes, I'd recommend switch your time data to datetime and the axes are aware and can dispense with datetick -- unless you've found another subset of specialty graphs TMW hasn't yet updated. In that case, submit bug reports to get them in the "todo" database
Rebecca Ellis
on 27 Jan 2019
I do not really know how you make a axis handle with many positions.
dpb
on 27 Jan 2019
Edited: dpb
on 27 Jan 2019
Looks like from your comment you misspelled the 'ColorOrder' property by having an extra trailing 'er'.
I would guess Oliver Ferdinand's patch is highly important in general, too.
(Somebody really ought to post a patched version instead of leaving this as is, btw!)
It appears the user interface isn't such that the function returns the axes handle(s) directly; the comments indicate they were stuffed into 'UserData' of the original axis object and you've got to go spelunking therein to find them.
Or, if you add just one at a time, you should be able to retrieve it for the newest one as
hAxNew=gca; % retrieve lastest axes created/presumes addaxes leaves current
keeping this as an array of handles if you add more than one, of course, so you don't overwrite the previous.
With that handle, you can do anything to that axes you desire including using it as the target into which to plot with any plotting function that recognizes an axes handle as the target axes, or, if it's a function that doesn't, making it the current axes presuming the function plots into current axes.
If it's one of the real specialty plots, some of them have hardcoded figure or the like that forcefully creates a new axes "no matter what!".
Rebecca Ellis
on 27 Jan 2019
Thank you for your reply, I have fixed the problem in the flunction.
But there is still a problem.
The yellow data is upside down to the axis lable.
using
figure
plot(advN.harmonic_fit.thf, Umagadvh)
addaxis(EC_time, Mayflux)
% hold on
addaxis(advN.harmonic_fit.thf, udiradvh, '.');
addaxis(EC_time, oxygen_may1, 'ro-')
datetick 'x'
Rebecca Ellis
on 28 Jan 2019
Sorry the attached image
dpb
on 28 Jan 2019
So, which data are those? Presumably "Mayflux"? since the other styles seem accounted for...well, the yellow axes limits are [-30 0] and Matlab always uses increasing values upwards on axis by default so it's what it really is. If you want that axis to be reversed, then you have to do what you want to it by setting its properties as desired -- the discussion above on either retrieving the handle(s) of the axes objects created by addaxis to use now or later (best practice) or by doing whatever it is that is wanted to that axis while it is still gca (more risky because focus can be changed by user intervention or other actions).
See doc axes for all the properties of axes objects to adjust as desired...what you're probably looking for here is 'yDir' and possibly 'XAxisLocation'
Rebecca Ellis
on 28 Jan 2019
Edited: Rebecca Ellis
on 28 Jan 2019
There are so many issues I find with addaxis is there another way of making a three y axis graph plot? I think addaxis doesn't like quiver plots and bar graphs..
I have now tried to even do a subplot but the xaxis do not alight with quiver,
figure
subplot(2,1,1)
yyaxis left
quiver(EC_time', zeros(size(x_velocity)),x_velocity,y_velocity);
ylim([-0.05 0.05])
xlim([736838.387690925 736839.514656334])
datetick('x')
% axis equal
yyaxis right
bar(EC_time, Mayflux);
ylim([-40 40]);
xlim([736838.387690925 736839.514656334])
% axis equal
% addaxis(240,250,EC_time, zeros(size(oxygen_may1)),'k');
grid on
subplot(2,1,2)
hold on
plot(EC_time, oxygen_may1, 'ro-');
plot(EC_time, oxygen_may_optode1, 'go-');
% plot(EC_time, oxygen_may, 'ko-');
xlim([736838.387690925 736839.514656334])
datetick('x')
grid on
ylim([240 254]);
But this is not the best way to display the graph.
dpb
on 29 Jan 2019
If you'll look at the code for addaxis (and the documentation) you'll see it has plot hardcoded into it so that's all it will do on its own.
As said, however, I'm virtually positive you could "fool mother addaxis" by simply passing NaN to it as the data to create the additional axes if you like where it is placed; and then call whatever plotting routines you wish using that axes handle (which you can either retrieve from the user data where the author squirreled it away or by gca after the call).
dpb
on 29 Jan 2019
I don't have the time to spare to try to patch addaxis, but if you'll attach a .fig file with the 3-axis attempt (again presuming you like where the axis, just not the plot), I'll try to take a look at retrieving the axes handle and should be able to do what you want onto that axis ignoring addaxis from that point on.
Or, of course, you could edit it to eliminate the hardcoded plot and pass a plotting function handle--that may have "issues" with all the callback stuff that the author built into it. It appears written for a very specific subset of multiple axes plotting.
A search on File Exchange for "multiple y axes" returned a number of hits besides addaxis I've used none of them but it looks like https://www.mathworks.com/matlabcentral/fileexchange/4425-ploty4-m might be almost trivial to modify to simply add a third axis and replace the plot function hardcoded into all of these submissions with your specific other type plots...or at least show you the basics of generating axes of given size/position.
Rebecca Ellis
on 29 Jan 2019
My attempt with addaxis
figure
yyaxis left
quiver(EC_time', zeros(size(x_velocity)),x_velocity,y_velocity);
ylim([-0.05 0.05])
xlim([736838.387690925 736839.514656334])
datetick('x')
% axis equal
yyaxis right
bar(EC_time, Mayflux);
ylim([-40 40]);
xlim([736838.387690925 736839.514656334])
% axis equal
grid on
addaxis(plot(EC_time, oxygen_may3));
hold on
plot(EC_time, oxygen_may_optode1, 'go-');
datetick('x')
grid on
ylim([240 254]);
xlim([736838.387690925 736839.514656334])
but a need a comination of there graphs
figure
yyaxis left
quiver(EC_time', zeros(size(North_red)), East_red, North_red);
ylim([-0.05 0.05])
axis equal
datetick('x')
axis equal
yyaxis right
hold all
plot(EC_time, oxygen_may3, 'ro-');
plot(EC_time, oxygen_may_optode1, 'go-');
ylim([240 254]);
axis equal
title('ADV')
grid on
figure
yyaxis left
quiver(EC_time', zeros(size(North_red)), East_red, North_red);
axis equal
ylim([-0.05 0.05])
axis equal
datetick('x')
yyaxis right
bar(EC_time, Mayflux);
ylim([-40 40]);
axis equal
grid on
title('ADV / flux')
datetick('x')
Thank you for your advise, sorry I dont really understand everything you have written. An example would be great as I have many other graphs to make with 3 yaxis.
dpb
on 29 Jan 2019
I've got pressing deadlines to take too much time away from at present to invest a great deal of time at this instant, sorry...
I'd again make two suggestions--
1) Convert your time data to datetime from the deprecated datenum and you may just find that things work better as there is an overloaded plot function that will automagically get called and you can get rid of datetick
2) If that doesn't bring joy, download and look at the other FEX submission link I showed and see if its application of the third axis will give you a set of axes that you can live. It's much less complicated a solution and you should be able to modify it at will.
Answers (0)
See Also
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!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)