double x-axis on loglog scale

조회 수: 5 (최근 30일)
Samaneh Arzpeima
Samaneh Arzpeima 2019년 2월 20일
답변: Etsuo Maeda 2019년 2월 28일
Hello
I have read my data from an excel file(attached here) and ploted them on a loglog scale,now I want to show another xaxis on the top of my figure (except my current x axis at the bottom) with just different scale . I tried the code inside the %%---%% but it did not work.The code outside of this part goes well.
could you please give me some idea how to add a second x axis to my figure.
I appreciate your time in responding to whatever you can.
thank you
clear all
clc
numdata = xlsread('test.xls');
Mw = numdata(:,1);
Area = numdata(:,2);
moment=10.^( 1.5.*Mw + 9.1 )
figure(1)
loglog(moment,Area,'ko',...
'MarkerEdgeColor','w',...
'MarkerFaceColor','k',...
'MarkerSize',6)
%% ---------
% part to add x axis on top
ax1 = gca; % current axes
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position', ax1_pos,'Color', 'none')
set(ax2, 'XAxisLocation', 'top')
% % set the same Limits and Ticks on ax2 as on ax1;
set(ax2, 'XLim', get(ax1, 'XLim'))
set(ax2, 'XTick', get(ax1, 'XTick'))
nticks = 6;
tickpos=[7 7.5 8 8.5 9 9.5]
set(gca, 'XTick', tickpos)
set(ax2,'Ytick',[]);
%%----------
c=1.77e-10;
M0=moment;
yCalc2=(c.*moment.^(2/3))
hold on
loglog(moment,yCalc2,'c-','LineWidth',1)
sim_moment = numdata((1:9),3);
sim_Area = numdata((1:9),4);
loglog(sim_moment,sim_Area,'mh',...
'MarkerEdgeColor','w',...
'MarkerFaceColor','m',...
'MarkerSize',9)
xlabel('Moment (Nm)')
ylabel('Rupture Area (km^{2}) ')
saveas(gcf,'test.png')

채택된 답변

Etsuo Maeda
Etsuo Maeda 2019년 2월 25일
This code may help you.
X = rand(5);
loglog(X)
ax1 = gca;
ax1.Box = 'off';
hold on;
% create new axes with nothing but xaxis on top
ax2 = axes;
ax2.Color = 'none';
ax2.XAxisLocation = 'top';
ax2.YTick = [];
or
plotxx
https://jp.mathworks.com/matlabcentral/fileexchange/317-plotxx-m
HTH
  댓글 수: 1
Samaneh Arzpeima
Samaneh Arzpeima 2019년 2월 28일
It worked PERFECTLY!
Thank you So much

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

추가 답변 (1개)

Etsuo Maeda
Etsuo Maeda 2019년 2월 28일
You are welcome :-)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by