 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Styling a part of label in legend in Matplotlib
To style a part of label in legend, we can take the following steps −
- Create data point for x using numpy. 
- Plot a sine curve using np.sin(x) with a text label. 
- Plot a cosine curve using np.cos(x) with a text label. 
- To place the legend on the plot, use legend() method. 
- To display the figure, use show() method. 
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-1, 1, 10) plt.plot(x, np.sin(x), label="This is $\it{a\ sine\ curve}$") plt.plot(x, np.cos(x), label="This is $\bf{a\ cosine\ curve}$") plt.legend(loc='lower right') plt.show()  Output

Advertisements
 