- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does a 4-element tuple argument for 'bbox_to_anchor' mean in Matplotlib?
If a 4-tuple or B box Base is given, then it specifies the b box (x, y, width, height) that the legend is placed in.
Steps
- Create x and y data points using numpy.
- Plot x and y using plot() method, with label y=sin(x) and color=green.
- To place the legend at a specific location, use location 'upper left' and use legend box dimension with four tuples that was defined in the above description.
- 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(-2, 2, 10) y = np.sin(x) plt.plot(x, y, c='green', label="y=sin(x)") plt.legend(loc='upper left', bbox_to_anchor=(0.05, 0.75, 0.2, 0.2)) plt.show()
Output
Advertisements