Two histograms with different x axis /values

조회 수: 9 (최근 30일)
Turbulence Analysis
Turbulence Analysis 2022년 2월 11일
댓글: Turbulence Analysis 2022년 3월 2일
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
Voss
Voss 2022년 2월 11일
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
Name Size Bytes Class Attributes ans 1x35 70 char data 4650x4 148800 double
data(1:10,:)
ans = 10×4
-79.0908 131.4540 -0.3971 -0.7163 -76.9090 131.4540 -0.3315 -0.5731 -74.7272 131.4540 -0.2215 -0.3192 -72.5453 131.4540 -0.1336 0.0441 -70.3635 131.4540 -0.0808 0.1728 -68.1817 131.4540 -0.0107 0.2184 -65.9999 131.4540 0.0603 0.0918 -63.8181 131.4540 0.2081 0.0550 -61.6363 131.4540 0.3676 -0.0100 -59.4544 131.4540 0.4558 -0.0613
[min(data); max(data)]
ans = 2×4
-79.0908 -1.6367 -3.5377 -2.9382 82.3636 131.4540 4.3992 13.6677

댓글을 달려면 로그인하십시오.

채택된 답변

Voss
Voss 2022년 2월 11일
% 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
Voss
Voss 2022년 3월 2일
% 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]);
Turbulence Analysis
Turbulence Analysis 2022년 3월 2일
Excellent Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Turbulence Analysis
Turbulence Analysis 2022년 3월 2일
Excellent Thanks

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by