double x-axis on loglog scale
Show older comments
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')
Accepted Answer
More Answers (1)
Etsuo Maeda
on 28 Feb 2019
0 votes
You are welcome :-)
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!