- Using 'NumBins' to set the bin resolution.
- Overlaying each group’s 'binscatter' output in a loop.
- Using transparency to reduce visual clutter.
Graph grouped bin scatter plot
6 views (last 30 days)
Show older comments
I want to graph the distribution of several large sets of 2-D points by group. There are too many points to use gscatter -- the group that is plotted last obscures previously plotted points. binscatter and binScatterPlot depict my distributions in a useful way, but I cannot use them to plot multiple distributions to the same axes. Is there a way to graph a grouped bin scatter plot?
0 Comments
Answers (1)
Rahul
on 23 Jun 2025
Hi Samuel,
I understand you're looking to visualize the distribution of several large 2D point sets grouped by category, and that functions like 'gscatter' cause occlusion issues when plotting large data.
While 'binscatter' does not directly support grouping, you can still visualize multiple groups by plotting each group separately using a loop and overlaying the results. To avoid overplotting, you can apply a transparency filter using the 'FaceAlpha' property.
For compatibility with older MATLAB versions, you can avoid using properties like 'FaceColor' or 'XBinCount' which may not be supported. Instead, you can utilize the following parameters:
Here is how you can achieve the same in MATLAB:
figure;
hold on;
for i = 1:numGroups
idx = groupLabels == i;
h = binscatter(x(idx), y(idx), 'NumBins', [50 50]);
h.FaceAlpha = 0.4; % Add transparency to prevent occlusion
end
hold off;
xlabel('X');
ylabel('Y');
title('Grouped Bin Scatter Plot');
This approach should allow you to visualize multiple large datasets simultaneously without losing important distribution details.
For more information regarding usage of 'binscatter' function for plotting binned scatter plots, you can refer to the following documentation link:
Best!
0 Comments
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!