How can I create a plot with two y-axis such that the left axis has a linear scale and right axis has a log scale in MATLAB?
11 views (last 30 days)
Show older comments
I want to be able to create a plot with two Y-Axes such that one of them is linear and the other is logarithmic.
Accepted Answer
MathWorks Support Team
on 19 Aug 2010
Two Y-axes result from the PLOTYY function. These axes are independent of each other. Each of their properties can be set using the 'YAxisLocation' property associated with the axes created using PLOTYY.
There are two possible use cases for this issue:
1. Multiple figure windows, each with one plot
2. Single figure window with multiple subplots
1. Use Case 1:
close all;
x1 = 1:10;
y1 = 1:10;
y2 = 1:10;
for i=1:3,
figure(i);
plotyy(x1,y1,x1,y2);
end
rax = findall(0, 'YAxisLocation','right');
lax = findall(0, 'YAxisLocation','left');
set(lax,'Yscale','linear','box','off');
set(rax,'Yscale','log','box','off');
2. Use Case 2:
x1 = 1:10;
y1 = 1:10;
y2 = 1:10;
close all;
figure;
for i=1:3,
subplot(3,1,i)
plotyy(x1,y1,x1,y2)
end
rax = findall(0, 'YAxisLocation','right');
lax = findall(0, 'YAxisLocation','left');
set(lax,'Yscale','linear','box','off');
set(rax,'Yscale','log','box','off');
0 Comments
More Answers (0)
See Also
Categories
Find more on Specifying Target for Graphics Output 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!