top of page

MATPLOTLIB LIBRARY

Matplotlib Library can be used to create a variety of visualizations in Python, ranging from static to interactive and animated ones. Using pyplot, module of Matplotlib, makes plotting straightforward by providing functionality to control line styles, font properties, and axis formatting, among other things. Matplotlib supports a wide variety of plots and graphs, including histograms, bar charts, power spectra, error charts, and more. John D. Hunter created Matplotlib.

For installing Turtle Module:

>>> pip install matplotlib

For importing Turtle Module:

>>>import matplotlib.pyplot as plt

  

Matplotlib Functions-

It use the following methods:

  • Values- Create lists to define the x-axis and y-axis values

      >>> x = [1,2,3,5]

             y=[5,3,2,1]

  • Labels- Give names to the x-axis and y-axis

      >>> plt.xlabel('x-axis')
             plt.ylabel('y-axis')

  • Title- Giving a title to a graph

      >>> plt.title('Graph')

  • Ticks- Set the tick location of the x-axis and y-axis

      >>> plt.xticks(x)

             plt.yticks(y)

  • Show- Show all the graphs

      >>> plt.show()

  • Savefig- Save the graphs

      >>> plt.savefig("graph.png")

  • Grid- Show gridlines in the graph

      >>> plt.grid(True)

Charts of Matplotlib-

In Matplotlib, we can also create different charts by using Pyplot function.

  • Line Chart

      >>> plt.plot(x,y)

  • Bar Chart (Vertical Bar Chart)

      >>> plt.bar(x,height,[width])

  •  Bar Chart (Horizontal Bar Chart)

      >>> plt.barh(x,height,[width])

  • Histogram

      >>> plt.hist(x,[bins])

  •  Pie Chart

      >>> plt.pie(x,[explode])

  • Scatter Plot

      >>> plt.scatter(x,y,[s])

Line Graph-

Bar Chart-

Histogram-

Pie Chart-

For further information, please read the official document of Matplotlib Library. Click Here!

For Google Colab notebook based on Matplotlib Library for more programs. Click Here!

bottom of page