Matplotlib.pyplot.hist() in PythonLast Updated : 13 Jan, 2025CommentsImproveSuggest changesLike ArticleLikeReportThe matplotlib.pyplot.hist() function in Python is used to create histograms, which are graphical representations of data distribution. It divides the data into bins (non-overlapping intervals) and counts the frequency of values in each bin, plotting them as bars. Lets consider the data values and visualise histogram with help of an example:Pythonimportmatplotlib.pyplotaspltdata=[32,96,45,67,76,28,79,62,43,81,70,61,95,44,60,69,71,23,69,54,76,67,82,97,26,34,18,16,59,88,29,30,66,23,65,72,20,78,49,73,62,87,37,68,81,80,77,92,81,52,43,68,71,86]plt.hist(data)plt.show()Output: Histogram with hist() with default parametersUnderstanding the syntax and parametersSyntax: matplotlib.pyplot.hist(x, bins=None, range=None, density=False, histtype=’bar’, color=None, label=None)x: The data to be represented in the histogram.bins: Specifies the number of bins or the bin edges for the histogram.range: The lower and upper range of the bins.density: If True, the histogram is normalized to form a probability density.histtype: Defines the type of histogram (e.g., ‘bar’ for a traditional bar histogram).color: Sets the color of the bars.label: Label for the histogram, used in legends.Create a Histogram in MatplotlibUsing the Matplotlib library in python, we can create many types of histograms. Let us see a few examples to better understand the functionality of hist() function. In this example, we will create a histogram and pass the necessary parameters such as bins, color, density, etc.Pythonimportmatplotlib.pyplotaspltimportnumpyasnpmu,sigma=121,21x=np.random.normal(mu,sigma,1000)num_bins=100n,bins,_=plt.hist(x,num_bins,density=True,color='green',alpha=0.7)plt.xlabel('X-Axis')plt.ylabel('Y-Axis')plt.title('matplotlib.pyplot.hist() Example',fontweight='bold')plt.show()Output:Creating the histogramExample 2: Visualize the Specific Bars of Histogram In this example, we will create a histogram with different attributes using matplotlib.pyplot.hist() function. We define a specific set of colors for the bars of the histogram bars.Pythonimportnumpyasnpimportmatplotlib.pyplotaspltx=np.random.randn(10000,3)colors=['green','blue','lime']plt.hist(x,bins=20,density=True,histtype='bar',color=colors,label=colors)plt.legend(fontsize=10)plt.title('matplotlib.pyplot.hist() Example',fontweight='bold')plt.show()Output:different color bars in matplot.pyplot.hist() Comment More infoAdvertise with usNext ArticleMatplotlib MarkersSSHUBHAMSINGH10FollowImproveArticle Tags : AI-ML-DSData VisualizationPython-matplotlibSimilar ReadsMatplotlib.pyplot.hist2d() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.hist2d() Function The hist2d() function in pyplot module of matplotlib library is used2 min readMatplotlib.pyplot.hsv() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.hsv() Function The hsv() function in pyplot module of matplotlib library is used to set2 min readMatplotlib.pyplot.hot() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.hot() Function The hot() function in pyplot module of matplotlib library is used to set2 min readMatplotlib.pyplot.hlines() in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. Matplotlib.pyplot.hlines() The Matplotlib.pyplot.hlines() is used to draw horizontal lin2 min readMatplotlib.pyplot.axis() in Python Matplotlib is a plotting library for creating static, animated, and interactive visualizations in Python. Pyplot is a Matplotlib module which provides a MATLAB-like interface. Matplotlib is designed to be as usable as MATLAB, with the ability to use Python and the advantage of being free and open-so1 min readMatplotlib.pyplot.csd() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.csd() Function The csd() function in pyplot module of matplotlib library is used to plo3 min readMatplotlib.pyplot.gci() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot,2 min readMatplotlib.pyplot.ion() in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. The matplotlib.pyplot.ion() is used to turn on interactive mode. To check the status of4 min readMatplotlib.pyplot.axes() in Python Pyplot is another module of matplotlib that enables users to integrate MATLAB within Python environment, and thus providing MATLAB like interface and making Python visually interactive. Matplotlib.pyplot.axes() pyplot.axes is a function of the matplotlib library that adds axes to the current graph a2 min readmatplotlib.pyplot.imshow() in Python matplotlib.pyplot.imshow() function in Python is used to display images in a plot. It is part of the matplotlib library and allows you to visualize images as 2D data. This function is widely used for displaying images, matrices, or heatmaps where each value in the array corresponds to a color. Examp5 min readLike