How to put a boxplot on a scatterplot/histogram?

13 次查看(过去 30 天)
I'm trying to put a boxplot over the data points in this scatterplot but can't find anything. This is the code to setup the table for the scatterhistogram
tbl = table(swine, cc, depth);
s = scatterhistogram(tbl, 'swine', 'cc', 'GroupVariable', 'depth');
The scatterplot is attached. Many thanks
  5 个评论
Adam Danz
Adam Danz 2020-10-23
编辑:Adam Danz 2020-10-26
Yeah, I'm not sure I understand the reasoning behind the family of high-level, standalone visualizations such as scatterhistogram, that mirror other visualization functions but without the same level of customizability.
To make things even more confusing, there are inconsistencies in the param names between the two functions (ie, nbins vs NumBins, which appear to do the same thing).
TMW have made some improvements to the standalone functions, though. I submitted a feature request earlier this year because scatterhistogram wouldn't allow us to add anything to the axes such as yline(),text(), or even a marker to indicate mean/median values using plot(). boxchart() is another example of a standalone version of boxplot() but I recall being able to make these modifications in boxchart. It looks like theses capabilities have been added to scatterhistogram in the r2020b release.
I'm guessing that their motovation is to streamline the use of these functions without the need to manipulate handle properties but if you compare the inputs between the standalone versions and the customizable versions, they aren't that much different. The standalone versons also give TMW greater flexibility in updating the functions without worrying about backward compatibility associated with external property manipulation. Except for the most basic use cases, I bet a lot of newer users eventually migrate their visualization from the standalone versions to the customizable versions as in this thread.
dpb
dpb 2020-10-24
Yeah, seems like they waste a LOT of time on such trivia and neglect far more significant improvements. Meanwhile the code bloat just continues to mutiply.
It certainly is not clear who's driving the ship and where they think they're going.

请先登录,再进行评论。

回答(1 个)

Adam Danz
Adam Danz 2020-10-23
编辑:Adam Danz 2020-10-27
scatterhistogram() is its own class and does not provide access to its axes. Instead, use the older scatterhist(). It's output is a 1x3 vector of axis handles where the first handle is the axis to the scatter plot.
h = scatterhist(___);
hold(h(1), 'on')
boxplot(___)
However, the marginal histograms are normalized and the boxplots will likely be at a much larger scale than the histograms. To see the axis scale, turn on the axes using,
axis(h(3), 'on')
I suggest putting the boxplots elsewhere, perhaps in their own axes or within the scatter axes.
  3 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by