14 / 20

# Getting Stared with Matplotlib - Creating Histograms using Pyplot

In this assessment, we will learn how to create histograms using Matplotlib's Pyplot.

Histograms are a special form of bar chart where the data represent continuous rather than discrete categories. This means that in a histogram there are no gaps between the columns representing the different categories. Histogram’s data is plotted within a range against its frequency. Histograms are very commonly occurring graphs in probability and statistics and form the basis for various distributions like the normal -distribution, t-distribution, etc.

INSTRUCTIONS
• Let us start by importing Pyplot:

``````import << your code goes here >> as plt
``````
• Now let us create a variable `x` with the data that we will use to plot the histogram. Here we will use NumPy’s random.randn() method which generates data with the properties of a standard normal distribution i.e. mean = 0 and standard deviation = 1, and hence the histogram looks like a normal distribution curve.

``````import << your code goes here >> as np
x = np.random.randn(10000)
``````
• Next, we will set up the title and the axis labels:

``````plt.<< your code goes here >>("Histogram Example")
plt.<< your code goes here >> ("Random Data")
plt.<< your code goes here >> ("Frequency")
``````
• Now we will plot our histogram using the `hist` method:

``````plt.<< your code goes here >>(x, 10)
``````

We have used `10` here to divide the data into 10 equal strata or bins.

• And finally, we will show our plot:

``````plt.<< your code goes here >>
``````

Note - Having trouble with the assessment engine? Follow the steps listed here