Matlab Plotting more that 2 y axis - matlab

I have 3 lines on a plot, each with massively different unit scales. I would like to plot 1 yaxis left and 2 yaxis on the right side, currently I just reduced the one line's value by a factor. Also in the future I would like to have 2 axis on one side to maybe display SI units and empirical for a single line. Currently im using yyaxis left and yyaxis right for the left and right yaxis
Can matlab add 2 axis on one side?
How to do it?
Edit: If not, what shenanigans can achieve the same result?

Related

Matlab - Plot difference between two graphs in specific points

I have two graphs, one is the exact graph of a solution, the other is a numerical approach. I have 4 specific points in my figure (t=0.25,0.5,0.75,1), where I want to illustrate the difference between the two graphs with a straight line. I found the errorbars function but i don't see any use there. Hope you can help me!
Edit:
this is the example figure:
t = [0:0.25:1];
y = t.*4;
x = t.^2+3;
plot(t,y,t,x)
I have 4 points now, t=0.25; t=0.5; t=0.75; t=1; At this points, I just want a vertical line between the two plots. I already have tried this: plot([t(1),y(1)],[t(1),x(1)])
but it just creates a line over the whole figure.
✶ It seems that you're not using hold on before using plot command the second time because otherwise you'd have got the desired result (which is actually not a correct way of plotting a vertical line).
✶ You're mixing up the values of x and y for plot(x,y). To plot a vertical line, it should be used like this: plot([x,x], [y1,y2])
For your case, you may not notice the difference between plot([t(1),y(1)],[t(1),x(1)]) (which is incorrect) and plot([t(1),t(1)],[x(1),y(1)]) (which is correct) because it is by chance that the values are same. Plot it for some other points and you'll realize the difference.
Fixed Code:
t = [0:0.25:1];
y = t.*4;
x = t.^2+3;
plot(t,y,t,x)
hold on
plot([t(1) t(1)],[x(1) y(1)])
% You have 't' on your horizontal axis and 'x'and 'y' values on the vertical axis
axis equal % just for better visualization
Output:

Horizontal line in Matlab with date on x axis

I have a piece of code in Matlab where I need to plot a graph including to lines depending on dates (x axis). I want then to add an horizontal line at y=0 to mimic the x axis as it is not shown due to negative value.
Here is the code:
figure1 = figure('Name','Historical Performance');
plot(QuarterEnd,perf(1,:),'b',QuarterEnd,perf(2,:),'r','DatetimeTickFormat','QQQ-y','LineWidth',2)
xlabel('Quarter');
ylabel('Performance');
ax = gca;
ax.XTickLabelRotation=45;
legend('Historical performance from prediction','Best Historical performance','LOcation','Southwest');
I have tried something like
line(QuarterEnd,[0 0],'Color','g')
But it does not span the right interval. I only need the line to be displayed over the interval where there are data points. Is there an easy way to do so?

Custom X axis in core plot

I have this X axis in my sample project on Core Plot and I wonder how I can customise it a little bit. As you can see it currently has only 3 values on the X axis:
But the values of the two plots I have (the black and grey ones) go far beyond the number of points in the X axis (29 against 3 points). Because of the fact that I have 3 points, only 3 values for each plot are shown.
I would like to keep displaying the remaining 3 points on the axis but accommodate all my 29 events for my plots (they could be displayed in the middle of 1 and 2 point).
How can I do this?
Increase the length of the xRange of the plot space. The value needed depends on the plot data.

double axis used in matlab

I am using a plotyy in matlab to plot two data set in a same figure. The left and right axis are of the different range. But I just find that on the right axis, there seems to be two different set of scale shown. I think one of them is really from the left axis.
t=-1:0.02:1;
y=sin(t);
y1=2*sech(t);
[AX, H] =plotyy(t, y, t, y1);
ylim(AX(2), [0 3.25]);
set(AX(2), 'YTickMode', 'auto')
After searching that online, I found that to turn off the box will solve the problem too. But the problem is to turn the box off will case the top horizontal line gone also. Is that anyway to remove the extra scale and keep the frame? Thanks.
It is possible and not terribly difficult, here's an illustrative example figure based on your test code
What I've done is to add a third axis (in this case I accomplished this by taking a shortcut - I called plotyy twice resulting in an extra blue line in the first axis and an extra second axis with a green line).
The idea is to turn the bounding box off for both the first and second axes, and then to turn it on for the third. That results in the top axis giving you the left vertical axis, the second the right vertical axis, and the third the top horizontal axis.
I don't think there's simple a way to do what you want. If you turn off the box (to get rid of the blue ticks on the right hand side) then the top horizontal line will disappear:
set(AX(1), 'Box','off')
If you want you could re-draw the line back in with:
line([-1, 1], [1, 1])
Or more generally:
lims = get(AX(1),{'XLim','YLim'});
line(lims{1}, lims{2}([2 2]))

Two left Y axis [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Plotting 4 curves in a single plot, with 3 y-axes
Dear stackoverflowers,
I need to plot 3 curves with same X axis (time) but three different dimensions (Volt, temp, current). The best outlook, to me, would be to have two Y axis on the left side, separated by a few pixel so we can read legend and ticks for each.
The answer to my questions are not plotyy neither multiple X or Y axis . In the first case, it helps me plot two different dimensions, not three.
the latter helps me associate right or left Y axis to a particular curve. I used the YAxisLocation option for my third curve but if I put it right or left, of course it interfers with the other YAxis that was there before. There is no option like left - 20 pixels ?
Thank you for your help.
You could just use plot (which will take care of the scale) and then include a legend to say what your units are (e.g. volts, degrees, etc)