double x-axis on loglog scale
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!