How to add multiple axes to a log-log plot?

조회 수: 4 (최근 30일)
Christian
Christian 2015년 7월 9일
댓글: Christian 2015년 7월 9일
I would like to create a log-log-plot with multiple x-axes. My goal is to display my data 'y' as function of 'x' and as a function of 'u=a*x' simultaneously. I have seen examples of plots with multiple axes but did not come across any log-log plot. Is there a way to achieve this?
Any hint would be appreciated, Christian

채택된 답변

Thorsten
Thorsten 2015년 7월 9일
편집: Thorsten 2015년 7월 9일
You have to set the xscale and yscale property of ax2 to 'log':
x1 = 1:1000;
y1 = x1.^2;
x2 = 2*x1;
y2 = y1;
loglog(x1,y1,'r')
hold on,
ax2=axes('xaxislocation','top','yaxislocation','right','color','none', 'xscale', 'log', 'yscale', 'log')
hold on
loglog(x2,y2,'g')

추가 답변 (2개)

Thorsten
Thorsten 2015년 7월 9일
  댓글 수: 1
Christian
Christian 2015년 7월 9일
Thanks for pointing out this possibility. However, I'd like to have two different x-axis whereas a single y-axis is fine. 'plotyy' provides just the opposite.

댓글을 달려면 로그인하십시오.


Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 9일
Look at this example
x1=0:0.01:5
x2=10*x1
y1=sin(x1)
y2=2*cos(x2)
plot(x1,y1,'r')
hold on,
ax2=axes('xaxislocation','top','yaxislocation','right','color','none')
hold on
plot(x2,y2,'g')
  댓글 수: 1
Christian
Christian 2015년 7월 9일
Thanks for your suggestion which works fine for plots with a linear scale. As I want to create a log-log plot, I tried replacing the 'plot' commands by 'loglog' commands. Unfortunately, doing this, produces strange results.
For example:
x1 = 1:1000;
y1 = x1.^2;
x2 = 2*x1;
y2 = y1;
loglog(x1,y1,'r')
hold on,
ax2=axes('xaxislocation','top','yaxislocation','right','color','none')
hold on
loglog(x2,y2,'g')
This piece of code should produce two straight lines with the same slope. Instead, it creates a straight line and a parabola as the second set of axes has a linear scale.
Any idea how to overcome this problem?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by