multiple logarithmic x-axes

I need to draw two plots with multiple logarithmic axes in the same figure. For clarification, I want two log-axes (one on top one in bottom) with the same y axis scale. attached is the current plot I got. I need to separate mu_s and mu_d axes.

댓글 수: 2

KSSV
KSSV 2019년 7월 17일
loglog ??
Mos_bad
Mos_bad 2019년 7월 17일
attached is the plot. I want to plot it with multiple x-axes. I mean to separate mu_s and mu_d

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

답변 (1개)

Shashank Sharma
Shashank Sharma 2019년 7월 17일

1 개 추천

댓글 수: 4

Mos_bad
Mos_bad 2019년 7월 17일
this document is about linear axes
Shashank Sharma
Shashank Sharma 2019년 7월 17일
편집: Shashank Sharma 2019년 7월 17일
The example is provided using the linear axes.
You can always do the same for the semilog or the loglog plot.
Here is an example,
x = 0:1000;
y = log10(x);
semilogx(x,y);
ax1 = gca;
ax1_pos = ax1.Position;
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','left',...
'Color','none',...
'YColor', 'none');
x = 0:1000;
y = 2*log10(x);
hold on;
semilogx(ax2, x,y);
ax1.YLim = max(ax1.YLim, ax2.YLim);
In the above code there are two plots on the same figure.
The yaxis is made transparent on the second axes and in the last line the limit of the Y-axis is changed to the max of both the axes so that it fits both plots in the same figure.
If you instead require a log-log plot use the loglog function instead of the semilog. It works on similar principles.
Xiaozhun Tang
Xiaozhun Tang 2020년 4월 8일
This is the figure by your code, you can see that the top axis is not logarithmic, how to solve this?
Tommy
Tommy 2020년 4월 8일
편집: Tommy 2020년 4월 8일
"If you attempt to add a loglog, semilogx, or semilogy plot to a linear axis mode graph with hold on, the axis mode remains as it is and the new data plots as linear."
If you take away the hold on call, however, all axes properties other than position or units will be reset upon plotting. (See NextPlot documentation and this line from hold documentation:
"The hold function sets these properties:
  • NextPlot axes property - Sets this property of the associated Axes, PolarAxes, or GeographicAxes object to either 'add' or 'replace'.").
One option is to set the axes properties after plotting:
x = 0:1000;
y = log10(x);
semilogx(x,y);
ax1 = gca;
ax1_pos = ax1.Position;
ax2 = axes('Position',ax1_pos);
x = 0:1000;
y = 2*log10(x);
semilogx(ax2,x,y);
set(ax2, 'XAxisLocation', 'top');
set(ax2, 'Color', 'none');
ax1.YLim = max(ax1.YLim, ax2.YLim);
Another option, if you don't want to have to reset the axes properties every time you add a new plot to the axes, or if you do want the ability to add multiple plots to ax2, is to set the XScale of ax2 to 'log':
x = 0:1000;
y = log10(x);
semilogx(x,y);
ax1 = gca;
ax1_pos = ax1.Position;
ax2 = axes('Position',ax1_pos,...
'XAxisLocation', 'top',...
'Color','none',...
'XScale', 'log',...
'NextPlot', 'add'); % set NextPlot to 'add' so that the above properties are not reset.
x = 0:1000;
y = 2*log10(x);
plot(ax2,x,y);
ax1.YLim = max(ax1.YLim, ax2.YLim);

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

카테고리

도움말 센터File Exchange에서 Axes Appearance에 대해 자세히 알아보기

질문:

2019년 7월 17일

편집:

2020년 4월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by