How can I have a graph with two logarithmic y axes?
조회 수: 16 (최근 30일)
이전 댓글 표시
I am trying to get a graph with two y variables, both having individual y axes. The y axes and the x-axis should all be logarithmic.
Creating the two y axes using yyaxis seems to work. However, when I try to modify both axes, only the secondary y-axis seems to be in a logarithmic scale. The primary y-axis is linear.
My code:
loglog(f,Gp,'x','MarkerSize',6,'LineWidth',3);
yyaxis left
ylabel('G_{prime} (Pa)')
yyaxis right
ylabel('G_{doubleprime} (Pa)');
hold on
loglog(f,Gdp,'x','MarkerSize',6,'LineWidth',3);
xlabel('Angular Frequency (rad/s)');
set(findall(0,'YAxisLocation','right'),'Yscale','log');
set(findall(0,'YAxisLocation','left'),'Yscale','log');
Attempted solutions:
- I have tried to change both the order and the position of the set(findall(...)) function, but to no avail.
- I have also attempted to solve the problem with plotyy(f,Gp,f,Gdp,@loglog,@loglog). This also did not provide me with the desired result.
- Interchanging the 'loglog' function that creates the plots with 'plot', 'semilogy', or 'semilogx' does not work either.
Some other details:
- Gp, Gdp and f are all 73x1 double.
- Both curves are visible.
- No errors are printed to the console.
Can anyone provide a solution?
댓글 수: 0
채택된 답변
Walter Roberson
2017년 10월 26일
My tests show that it is creating a log plot. However, in that range of y values, it is not visibly apparent that the line spacing is log rather than linear. If you compare the plot to semilogx(1:73, log(Gp)) you will see the shape is correct for the loglog plot.
추가 답변 (1개)
Steven Lord
2017년 10월 26일
This code worked fine for me in release R2017b on Windows and showed two Y axes and one X axis, all three in log scale. Try it in your MATLAB session. If it doesn't work for you, use print to create an image from the figure and use the Image button (the one with a green rectangle inside a brown frame) above the comment entry box to include it in your response.
x = 1:10;
y1 = 5*x;
y2 = x.^2;
yyaxis left
h = loglog(x, y1);
yyaxis right
h2 = loglog(x, y2);
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!