How to Change the Transparency of a Graph Plot in Matplotlib with 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 that can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, etc.
In order to change the transparency of a graph plot in matplotlib we will use the matplotlib.pyplot.plot() function. The plot() function in pyplot module of matplotlib library is used to make 2D illustrations.
Syntax: matplotlib.pyplot.plot(\*args, scalex=True, scaley=True, data=None, \*\*kwargs)
Parameters: This method accept the following parameters that are described below:
- x, y: These parameter are the horizontal and vertical coordinates of the data points. x values are optional.
- fmt: This parameter is an optional parameter and it contains the string value.
- data: This parameter is an optional parameter and it is an object with labelled data.
Returns: This returns the following:
- lines : This returns the list of Line2D objects representing the plotted data.
Another argument that we are going to use is alpha argument, this argument is responsible for the transparency of any illustration depicted using matplotlib library. Its value ranges from 0 to 1, by default its value is 1 representing the opaqueness of the illustration.
Below are some examples which depict how to change the transparency of a Graph Plot using matplotlib library
In the above program, the linear graph is depicted with transparency i.e alpha=0.25.
Here, the plot is quite opaque as the alphavalue is close to 1(opaque).
The above example depicts a signal with an alpha value 0.1.
The above program depicts the same illustration with variable alpha values.