# contourhist(h, varargin)

Version 1.0.0.0 (1.6 KB) by
Draw a histogram contour using the histogram object information (from Matlab's "histogram" function)
Updated 27 Apr 2016

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
Created with R2015a
Compatible with any release
##### Platform Compatibility
Windows macOS Linux
##### Categories
Find more on Data Distribution Plots in Help Center and MATLAB Answers