Two histograms with different x axis /values
26 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Turbulence Analysis
le 11 Fév 2022
Commenté : Turbulence Analysis
le 2 Mar 2022
Hi,
I am trying plot histogram with two different x values on the single plot. Did somebody tried something similar like this before..
For example, as shown in the attached files, data in the file A spans from 0 to 100, and whereas data in file B spans over 0 to 2500..
1 commentaire
Voss
le 11 Fév 2022
It's not clear how the contents of the attached .mat file relate to the data in file A and file B as described.
load('matlab.mat');
whos
data(1:10,:)
[min(data); max(data)]
Réponse acceptée
Voss
le 11 Fév 2022
% some data:
A = 12*randn(1,100)+50;
B = 300*randn(1,1000)+1250;
% some histograms from the data:
histogram(B);
hold on
histogram(A);
17 commentaires
Voss
le 2 Mar 2022
% some data:
A = 12*randn(1,100)+50;
B = 300*randn(1,1000)+1250;
C = 12*randn(1,100)+50;
figure();
ax_b = gca();
ax_a = copyobj(ax_b,gcf());
colors = get(ax_a,'ColorOrder');
n_bins = 20;
% some histograms from the data:
h_a = histogram(ax_a,A,n_bins,'FaceColor',colors(2,:),'FaceAlpha',0.5);
h_b = histogram(ax_b,B,n_bins,'FaceColor',colors(1,:),'FaceAlpha',0.5);
set(ax_a,'NextPlot','add');
h_c = histogram(ax_a,C,n_bins, ...
'BinEdges',get(h_a,'BinEdges'), ...
'FaceColor',colors(3,:),'FaceAlpha',0.5);
ylabel(ax_a,'A, C');
ylabel(ax_b,'B');
set(ax_a, ...
'Box','off', ...
'Color','none', ...
'XAxisLocation','top', ...
'YAxisLocation','right', ...
'XColor',colors(2,:), ...
'YColor',colors(2,:));
set(ax_b, ...
'Box','off', ...
'XColor',colors(1,:), ...
'YColor',colors(1,:));
legend([h_a h_b h_c]);
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Data Distribution Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!