How to Customize Histograms in MATLAB
Learn how to leverage simple MATLAB® functions to customize the appearance of a histogram. You’ll learn how to accomplish tasks like changing the bin size and displaying relative frequencies on the y-axis instead of absolute counts.
Published: 10 Feb 2021
This video demonstrates how to leverage simple MATLAB functions to customize the appearance of a histogram. You’ll learn how to accomplish tasks like changing the bin size and displaying relative frequencies on the y-axis instead of absolute counts.
In the first section, we generate 10,000 random numbers of standard normal distribution. The histogram function helps us visualize this data using default settings.
We can implement some useful customizations by passing additional parameters to the function. If we want to group our data into larger buckets, we simply pass in an array that specifies the bin edges; in this case, we’ll get bins of width 0.5 from -4 to 4.
Furthermore, we can change the histogram to display relative frequencies instead of absolute counts. How much of this data is concentrated in this highest bin? Hard to tell, but if we run the function with these parameters, we quickly see the answer is about 20%.
Finally, to give us more control on how our histogram is visualized, we’ll convert the histogram into a bar graph. We simply replace “histogram” with “histcounts” to get the count in each bin, and the bin edges. Note that we only need to supply the “count” variable to the bar function to reproduce the shape of the histogram. If we care about the x-axis matching up exactly with our previous histogram, we can use this code.
Now that we’re working with a bar graph, we can quickly apply useful customizations. First, we’ll modify the y-axis ticks to display percentages, and adjust the count to match. And as with any good graph, we should add a title, and label the axes.
To learn more about histograms and other customizations for MATLAB graphs, check out the links in the description.
Up Next:
Related Videos:
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia-Pacífico
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)