contourhist(h, varargin)
Sometimes, overlapping histograms overwhelms our visual system. Due to the transparency of the histogram bars the resulting figure looks like having "aliasing" histograms. The function submitted here uses a contour approach. Just plot your overlapped histograms with no transparency (h.FaceAlpha =1) and call this function as many times as histograms you created (using the corresponding histogram object information). See the example. I hope you like it.
Example used for image above:
clear
close all
clc
A1 = randn(1,10^4)+3.8;
A2 = randn(1,10^4)+1.4;
A3 = randn(1,10^4);
figure
h1 = histogram(A1);
h1.NumBins = 24;
h1.BinWidth = 0.25;
hold on
h2 = histogram(A2);
h2.NumBins = 24;
h2.BinWidth = 0.25;
h3 = histogram(A3);
h3.NumBins = 24;
h3.BinWidth = 0.25;
hold off
figure
h1 = histogram(A1);
h1.NumBins = 24;
h1.BinWidth = 0.25;
h1.FaceAlpha =1;
hold on
h2 = histogram(A2);
h2.NumBins = 24;
h2.BinWidth = 0.25;
h2.FaceAlpha =1;
h3 = histogram(A3);
h3.NumBins = 24;
h3.BinWidth = 0.25;
h3.FaceAlpha =1;
hc1 = contourhist(h1, 'Color', [0 0 0], 'LineWidth', 6);
hc2 = contourhist(h2, 'Color', [0 0 0], 'LineWidth', 6);
hc3 = contourhist(h3, 'Color', [0 0 0], 'LineWidth', 6);
hold off
Cite As
Javier Lopez-Calderon (2024). contourhist(h, varargin) (https://www.mathworks.com/matlabcentral/fileexchange/56797-contourhist-h-varargin), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- MATLAB > Graphics > 2-D and 3-D Plots > Data Distribution Plots >
- MATLAB > Graphics > Graphics Objects > Specifying Target for Graphics Output >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |
Description uploaded
|