Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article in Python

  • Last Updated : 13 Apr, 2020

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. Function

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

The function in axes module of matplotlib library is used to make a bar plot.

Syntax:, x, height, width=0.8, bottom=None, *, align=’center’, data=None, **kwargs)

Parameters: This method accept the following parameters that are described below:

  • x: This parameter is the sequence of horizontal coordinates of the bar.
  • height: This parameter is the height(s) of the bars.
  • width: This parameter is an optional parameter. And it is the width(s) of the bars with default value 0.8.
  • bottom: This parameter is also an optional parameter. And it is the y coordinate(s) of the bars bases with default value 0.
  • alighn: This parameter is also an optional parameter. And it is used for alignment of the bars to the x coordinates.

Returns: This returns the following:

  • BarContainer:This returns the container with all the bars and optionally errorbars.

Below examples illustrate the function in matplotlib.axes:

Example #1:

# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
data = ((30, 1000), (10, 28), (100, 30),
        (500, 800), (50, 10))
dim = len(data[0])
w = 0.6
dimw = w / dim
fig, ax = plt.subplots()
x = np.arange(len(data))
for i in range(len(data[0])):
    y = [d[i] for d in data]
    b = + i * dimw, y, 
               bottom = 0.001)
ax.set_xticks(x + dimw / 2)
ax.set_xticklabels(map(str, x))
ax.set_title(' Example')


Example #2:

# ImpleMinetation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
labels = ['Month1', 'Month2', 'Month3', 'Month4']
mine = [21, 52, 33, 54]
others = [54, 23, 32, 41]
Mine_std = [2, 3, 4, 1]
Others_std = [3, 5, 2, 3]
width = 0.3
fig, ax = plt.subplots(), mine, width, 
       yerr = Mine_std, 
       label ='Mine'), others, width, 
       yerr = Others_std,
       bottom = mine,
       label ='Others')
ax.set_title(' Example')


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!