A histogram plot is a graph that shows the distribution of a continuous data set through vertical columns. The width of the column represents the data intervals. The height of each column represents how often the values fall within a given interval. This chart is often used to identify mode values (the values that appear most frequently) in a set of continuous values.
Draw a histogram plot with Python using matplotlib.pyplot.hist()
:
import matplotlib.pyplot as plt
import numpy as np
# Generate some sample data
data = np.random.normal(170, 10, 250)
print(data)
# Create the histogram
plt.hist(data, bins=30, color='skyblue', edgecolor='black')
# Add labels and title
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.title("Histogram of Sample Data")
# Display the plot
plt.show()
Output:
[161.26848244 171.23389977 195.18047839 146.05461735 181.68440656
171.19324883 162.6545889 183.82255376 158.32533123 158.664465
165.19799157 159.43072342 185.35883134 161.4548304 164.98437497
154.76595065 170.40977342 155.23154333 174.98670739 170.75991482
173.73664235 177.81551435 170.86320401 162.2567852 173.74009483
153.26719022 157.16487846 172.60642596 161.38174712 182.56366728
168.881977 166.93759022 165.61529054 167.78276416 172.33906668
179.57474113 177.35469089 191.24951642 165.48415953 180.21268166
164.31723613 164.42359515 183.24940499 152.25783051 162.55506896
171.19069194 160.67284606 161.32757709 177.4220677 168.7410962
175.83597344 179.83393371 181.36792437 158.38193769 165.7910599
158.83492618 169.45635775 166.90570698 163.90610268 152.48219691
174.85536001 167.12955337 153.27137055 189.36213475 155.8800153
176.29266633 183.38517679 186.02584137 171.12656742 166.52871834
166.44249802 180.45280315 177.69581425 180.47998388 161.99435099
160.56404998 166.77486222 167.15228075 176.3302318 174.13012678
163.36975806 180.45406579 180.66699821 192.5724722 183.02761178
183.24130216 190.0234818 166.73060873 180.09765409 178.73199379
175.15588787 165.0010754 161.10766524 156.35030343 166.26987075
178.26160399 147.46213981 166.32295499 170.24993675 147.77343162
172.53471521 167.6799597 159.01370096 169.35881682 187.11764773
172.01904317 170.70199804 172.67700163 176.42153664 165.73361399
166.728095 169.03537414 181.92042395 196.56065247 185.5270646
173.79859147 149.90927899 162.9953941 175.10954564 156.72754483
157.81487522 155.56269498 144.59398011 162.17317133 181.57692738
169.9068084 174.89889978 165.71012405 175.64992737 163.85293071
161.59720273 165.58882674 179.19188464 160.26350643 183.88378632
178.46334336 175.20469387 177.31301689 158.02679952 178.97778429
163.16689244 182.36086077 173.75968127 158.5780822 169.15859263
162.618716 176.27818545 173.83739709 169.87333454 165.73578256
158.61841903 165.59839035 177.51857019 165.11702202 177.45447938
160.11082482 158.17007559 159.64481073 184.97754645 166.4002771
174.36157541 149.90769785 158.22642419 152.23112893 156.77057133
184.99087373 170.81721541 160.93908481 161.99876699 165.16680622
184.96423996 165.6300002 171.03485409 164.37125598 178.026291
171.37456097 172.35539201 166.20354583 179.55239504 165.81308764
181.8642972 138.9334139 170.64013028 189.71871924 186.74567785
187.78165891 171.26451372 182.91345798 184.98902302 171.5605168
169.70113965 176.86101272 181.44612435 155.82148729 167.87890978
173.56753888 175.05843499 175.5307862 160.80734213 161.47096999
164.22630228 187.068885 157.78346166 182.87828275 189.14745621
166.7349727 178.31225079 176.26773513 152.54606108 160.8174765
164.36615653 162.49414557 177.30147183 153.90634473 155.19628611
172.14093316 175.42553984 159.28814676 155.38822521 157.79209869
163.51366597 183.22517169 175.21845307 169.41421491 180.78404555
168.76692327 169.94773562 165.51790136 185.60976181 165.07521663
175.50402971 162.52610671 168.64915596 158.58137564 178.3508014
180.97074803 151.62830737 179.94585918 156.91233155 184.83803485
176.11419841 170.19898184 158.27344175 151.80566791 164.58729717
163.63429787 162.63038258 165.50006066 154.22780676 186.69857259]