double x-axis on loglog scale

4 views (last 30 days)
Samaneh Arzpeima on 20 Feb 2019
Answered: Etsuo Maeda on 28 Feb 2019
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')
0 CommentsShowHide -1 older comments

Sign in to comment.

Accepted Answer

Etsuo Maeda on 25 Feb 2019
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 CommentShowHide None
Samaneh Arzpeima on 28 Feb 2019
It worked PERFECTLY!
Thank you So much

Sign in to comment.

More Answers (1)

Etsuo Maeda on 28 Feb 2019
You are welcome :-)
0 CommentsShowHide -1 older comments

Sign in to comment.

Categories

Find more on Annotations 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!

Translated by