I wanna add upper axis to my plot to be the same as in the attached picture.

3 views (last 30 days)
the code is ready, but i just wanna add upper x axis as the plot in the picture, please help if you can.... if you run the code will give the same plot but without the upper x axis.
clear all,
% generate some data
dollarlost = logspace(4, 12, 81);
liveloss = logspace(-2,6,81);
p3 = 1e5./dollarlost;
p2 = 1e4./dollarlost;
p1 = 1e3./dollarlost;
loglog(dollarlost, p1, 'g-', dollarlost, p2, 'b--', dollarlost, p3, 'r:')
grid on
ylim([1e-7, 1])
xlabel('DOLLARS LOST');
ylabel('ANNUAL PROBABILITY OF FAILURE');
%t = tiledlayout(1,1);
%ax1 = axes(t);
%loglog(dollarlost, p1, 'g-', dollarlost, p3, 'r:');
%ax2 = axes(t);
%loglog(liveloss,p2);
%ax2.XAxisLocation = 'top';
%ax2.Color = 'none';

Answers (1)

GandaBerunda
GandaBerunda on 8 Jul 2022
Hi Khaled,
You had to pass the target axes in loglog:
clear all
% generate some data
dollarlost = logspace(4, 12, 81);
liveloss = logspace(-2,6,81);
p3 = 1e5./dollarlost;
p2 = 1e4./dollarlost;
p1 = 1e3./dollarlost;
t = tiledlayout(1,1);
ax1 = axes(t);
loglog(ax1,dollarlost, p1, 'g-', dollarlost, p2, 'b--', dollarlost, p3, 'r:')
grid on
xlabel(ax1,'DOLLARS LOST');
ylabel(ax1,'ANNUAL PROBABILITY OF FAILURE');
ylim(ax1,[1e-7 1]);
ax2 = axes(t);
loglog(ax2,liveloss,p2,'k-');
ax2.XAxisLocation = 'top';
ax2.Color = 'none';
xlabel(ax2,'LIVES LOST');
ylim(ax2,[1e-7 1]);
Hope it helps.

Categories

Find more on Data Exploration in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!