# matplotlib.pyplot.hold with it’s examples

In this post, we will learn about matplotlib.pyplot.hold but before going right to it let’s understand briefly what matplot is.

The Matplotlib library allows you to plot data in two dimensions. Matplotlib allows users to plot graphs easily, a low-level Python library. . We can use it freely from online sources. Matplotlib is mostly used in python along with c and c++ but only to some extent. Easy things become easy with Matplotlib, and hard things become possible with Matplotlib.

## Installation of Matplotlib:

Follow the below-given command to install Matplotlib in your system if you already have python and pip installed.

pip install matplotlib

## Importing Matplotlib:

After installing matplotlib you can import your code by using the import command below:

import matplotlib

Matplotlib is now ready for our use.

## pyplot:

Matplotlib is a library that has pyplot as its submodule and most services of Matplotlib lie under it. But how will you import it? Follow the given code:

import matplotlib.pyplot as plt # Henceforth, Pyplot will be called plt.

### Example:

import matplotlib.pyplot as plt import numpy as np x_coordiantes = np.array([0, 10]) y_coordinates = np.array([0, 200]) plt.plot(x_coordinates, y_coordinates) plt.show()

#### Output:

## matplotlib.pyplot.hold:

Now, what is .hold? The hold function behaves the same way as in matplotlib and pyplot. A plot command set to ‘on’ will display a new plot on top of the existing plot without clearing the current one. In this way, incremental plotting is possible.

hold() # toggle hold hold(True) # hold is on hold(False) # hold is off

### Example:

lines = plot(linestyle='-', color='red') lines = plot(linestyle='-', color='blue', hold='on')

Python version 3.0 deprecates the **.hold** mechanism. The behavior will remain consistent with the long-time default value of True. The current plot axes will be added to subsequent plot commands when **.hold** is True. When you then plot the next command, the figure and current axis will be cleared if the hold was set to false.

Do you want to learn how we plot a line graph from a NumPy array? Follow this tutorial: Plotting of line graph from NumPy array

Know more about Numpy from this tutorial: How does NumPy.histogram2d works in Python

## Leave a Reply