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:
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- 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)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)