Graph grouped bin scatter plot

6 views (last 30 days)
Samuel Brudner
Samuel Brudner on 24 May 2018
Answered: Rahul on 23 Jun 2025
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?

Answers (1)

Rahul
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:
  1. Using 'NumBins' to set the bin resolution.
  2. Overlaying each group’s 'binscatter' output in a loop.
  3. Using transparency to reduce visual clutter.
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!

Tags

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!