How to plot a histogram along a curve
조회 수: 9 (최근 30일)
이전 댓글 표시
Hi,
I have (x,y) data that lie along a curve whose form I do not know analytically. I want to plot a histogram (or estimated PDF) of the data along this curve, and have the color of the curve indicate the bin count (or probability density). Using histogram2 I can produce something like the following, but I would much rather have the curve (shown here in black) indicate the probability density rather than these clunky 2D bins that have to be either above or below the curve at any point. Mostly this is because I want to overlay this PDF on top of another figure, but the only way I know how is to use a contour plot of q.Values, and this looks clunky and isn't very accurate, actually.
Does anyone know of a way to plot a PDF along a curve?
Thanks!
Dan
q = histogram2(x,y,30,'Normalization','pdf','DisplayStyle','tile','ShowEmptyBins','off','EdgeAlpha',0.0);
댓글 수: 4
dpb
2020년 1월 26일
Yes. One can compute/estimate an empirical cdf/pdf, and compare to a theoretical or other set of data, and maybe that's what's intended, but it's certainly not clear from the description as provided and w/o the data to look at and some background as to what it is we are looking at, it's imponderable..
답변 (2개)
dpb
2020년 1월 27일
Oh. That's much more understandable, thanks. Something like
histogram2(x.',y.','Normalization','pdf','FaceColor','flat')
colorbar
xlabel('X'),ylabel('Y')
maybe? Above generates the following after using the interactive rotation facility to get the particular perspective. Your data are so concentratred along the path there's not much disparity in the transverse direction...
댓글 수: 2
dpb
2020년 1월 29일
"to be able to plot a curve whose color changed as probability changed" is, unfortunately, not possible with a line as the line color is a single property of the line in a 2D axis, unfortunately. You could create line segments and set their color similar to what you've done before w/ scatter.
dpb
2020년 1월 29일
Well, your data is rather unique (so to speak :) ): I was trying to figure out how you did the opacity thing in knowing the relative frequency so I poked around some and discovered the interesting factoid:
>> ux=unique(x); uy=unique(y);
>> whos u*
Name Size Bytes Class Attributes
ux 1x562 4496 double
uy 1x562 4496 double
>>
That's most interesting, indeed!!! So,
>> n=histc(y,uy); % get a count for each unique; assume (didn't check) x,y go together
In that case, then one can create the illusion of a line with variable color as:
hS=scatter(ux,uy,3,n,'filled');
that results in:
One may need to poke around with color maps to make the range more apparent...
Otherwise, I'm pretty-much out of ideas...
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!