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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.