Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Khaled aL Qattawi
Khaled aL Qattawi le 8 Juil 2022
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';

Réponses (1)

GandaBerunda
GandaBerunda le 8 Juil 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.

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by