Learn Python

Learn Data Structure & Algorithm

Learn Numpy

Learn Pandas

Matplotlib Introduction

Matplotlib Bar Plot

Matplotlib Pie Chart

Matplotlib Hist Plot

Matplotlib Line Plot

Matplotlib Scatter Plot

Matplotlib Subplot

Matplotlib Save image

Learn Seaborn

Learn Statistics

Learn Math

Learn MATLAB

Learn Machine learning

Learn Github

Learn OpenCV

Learn Deep Learning

Learn MySQL

Learn MongoDB

Learn Web scraping

Learn Excel

Learn Power BI

Learn Tableau

Learn Docker

Learn Hadoop

Matplotlib hist plot

What is a Histogram?

It is used to represent the distribution of numerical data. Here the data is divided into a series of bins. In histogram each bar height represents the number of data points that comes inside that bins.

How to create a Histogram?

To create Histogram write module_name.hist(). In the bracket pass parameter.

Some mandatory parameters:
The first parameter is a variable name where you stored values for creating a histogram.

labels=["pass names as list"]. Used to set labels for every section.

Some other parameters:

colors=["colors name as a list"].Used to give colors of bars.Color name, RGB color, hex color, etc.

rwidth=0.0 to 1.0.Used to increase or decrease bar width.

How to give title,labels,legend,grid?
Title
For title write module_name.title().
In the bracket write the title as a string. For font size write fontsize:value . Between title name and font size parameter give a coma.

xlabel
For label at x-axis write module_name.ylabel().
In the bracket write the label name as a string. For font size write fontsize:value. Between label name and font size parameter give a coma.

ylabel
For the label at the y-axis write module_name. ylabel().
In the bracket write the label name as a string. For font size write fontsize:value. Between label name and font size parameter give a coma.

legend
If there are multiple bars and every bar defines different things, then you should use the legend to give a name for each bar so that you can understand which bar is for why.To give legend first write module_name.legend().Pass all the names as a list in the bracket. To set the position use the loc parameter. You can give the value of the loc parameter between 0 to 3

grid
For grid first write module_name.grid().
Some parameters of the grid are
1.color: used to set the color of the grid.Example: color="green".
2.linestyle: used to set grid line style.Example: linestyle="--".
3.linewidth: used to set line width of the grid.example: linewidth=2.

Input
import matplotlib.pyplot as plt
value1=[40,85,47,98,30]
value2=[55,90,61,78,20]
bins=[20,40,60,80,100]
plt.title("Histogram for practise")
plt.xlabel("x axis value")
plt.ylabel("y axis value")
plt.hist([value1,value2],bins,rwidth=0.6,color=["r","g"])
plt.grid(color="red",linewidth=2,linestyle=":")
plt.legend(["value1","value2"])
plt.show()

CodersAim is created for learning and training a self learner to become a professional from beginner. While using CodersAim, you agree to have read and accepted our terms of use, privacy policy, Contact Us

© Copyright All rights reserved www.CodersAim.com. Developed by CodersAim.