Plotting y1 and y2 versus time in the same graph with same axis level but both in the same side and different y axis name.

I am trying to plot two variables (like speed V_a, & V_b of two cars) versus time. I am trying to use same axis range for both V_a and V_b over the same interval of time. I want to keep both y variables in the left side. But, all I am trying is here distinguishing two plots with differnt color and mentioning name of both speeds in y axis. Please suggest me.

Answers (1)

Not sure what you mean about "mentioning both speeds in y axis". A more conventional method would be to use a legned. Does this work for you?
% Some pretend data
t = 1:0.05:5;
V_a = t;
V_b = t.^2;
figure
plot(t,V_a,t,V_b)
xlabel('Time')
ylabel('Speed')
legend({'V_a','V_b'},'Location','NorthWest')

4 Comments

Thank You. Your information surely helps. The only thing I have different in my actual work is different y variables. In my previous question I just wrote speed of two cars so y-level is common but they were separated in legend. I have two different quantities in y-axis although they are same dimensionally. Any suggestions?
I'm sorry, I don't understand what you mean. Maybe you could read the documentation for the plot command, to see if you can get what you want. Also, look at the MATLAB Plot Gallery for ideas.
I was trying to keep both V_a and V_2 in place of speed but looks like I can write like below. The y varaibles i.e. Tumor volume and Carrying capacity have same dimension but have different meaning so I don't have a single replacement like 'Speed' for both of them. Still, I utilized your idea like below.
Thank you!
.............................
plot(t,V,t,K)
xlabel('Time (days)')
ylabel('Tumor Volume/Carrying Capcity (mm^3)')
legend({'V','K'},'Location','NorthWest')
A different approach that displays the same information would be
% Pretend data
t = 1:0.05:5;
tumorVol = t.^2;
carryCap = t.^2/2;
figure
plot(t,tumorVol,t,carryCap)
xlabel('Time')
ylabel('Volume [mm^{3}]')
legend({'Tumor','Carrying capacity'},'Location','SouthEast')
You'll need to decide what will be clearest to your audience.
[Note that I also showed here how to change the location of the legend to the lower-right corner, and how to use an exponent for mm^3.]

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Asked:

on 18 Oct 2021

Commented:

on 18 Oct 2021

Community Treasure Hunt

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

Start Hunting!