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!