×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python | Legend Shadow

Legend Shadow in Python. Here, we are going to learn the legend shadow and its Python implementation.
Submitted by Anuj Singh, on July 20, 2020

It helps in the different look of the legend and also the most used feature in many presentations.

matplotlib.pyplot.legend(shadow=True)
Python | Legend Shadow (1)

Python | Legend Shadow (2)

Python code for legend shadow

# Data Visualization using Python
# Adding a Legend Shadow

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2, 100)

# Example 1
plt.figure()
plt.plot(x, x+2, 'o', color='orange', label='linear')  
plt.plot(x, x**2, linewidth=2.0, color='purple', label='quadratic')  
plt.plot(x, x**3, label='cubic')
plt.xlabel('x label')
plt.ylabel('y label')
plt.title("Legend with Shadow")
plt.grid()
plt.legend(shadow=True)

# Example 2
plt.figure()
x = np.linspace(0.0, 5.0)
y = x*x
plt.subplot(2, 1, 2)
plt.plot(x, y, 'g.-',label='quadratic')
plt.plot(x,x, '.-', color='purple', label='linear')
plt.title('Legend with Shadow')
plt.xlabel('numbers')
plt.ylabel('Square')
plt.legend(shadow=True)
plt.grid()
plt.show()

Output:

Output is as figure
Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.