How to provide shadow effect in a Plot using path_effect attribute in Matplotlib

In order to provide path effects like shadow effect in a plot or a graph, we can use the path_effect attribute.

For example, let’s see how we can use the path_effect attribute in Matplotlib add a shadow effect to a sigmoid function.

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patheffects import PathPatchEffect, SimpleLineShadow, Normal

Now let us define the size of the figure and plot the sigmoid function,'seaborn-deep')

Let us define the datapoints for the plot,

x = np.linspace(-10, 10, 50)
y = 1+ np.exp(-x))

Let us define the shadow property in the plot,

plt.plot(x, y, linewidth=8, color='blue', path_effects=
[SimpleLineShadow(), Normal()])
#Show the Plot


Updated on: 23-Feb-2021


Kickstart Your Career

Get certified by completing the course

Get Started