Python | Text Box Styles in Matplotlib

Here, we are going to learn about the text box styles in matplotlib and its Python implementation.
Submitted by Anuj Singh, on July 19, 2020

In this tutorial, we are going to see the types of Text-Box styles (Square, Rounded, and Circle. We can manually set the textbox style by using bbox=dict(boxstyle=" ",) In this tutorial, we are going to see the types of Text-Box styles (Square, Rounded, and Circle. We can manually set the textbox style by using bbox=dict(boxstyle=" ",).

Following are the illustrations:

bbox=dict(boxstyle="square", ec=(1., 0.5, 0.5), fc=(1., 0.8, 0.8))
# Square textbox style
Python | Text Box Styles in Matplotlib (1)
bbox=dict(boxstyle="round", ec=(1., 0.5, 0.5), fc=(1., 0.8, 0.8))
#round textbox style
Python | Text Box Styles in Matplotlib (2)
bbox=dict(boxstyle="circle", ec=(1., 0.5, 0.5), fc=(1., 0.8, 0.8))
#Circular textbox style
Python | Text Box Styles in Matplotlib (3)

Python code for text box styles in matplotlib

import matplotlib.pyplot as plt

# Square
plt.figure()
plt.text(0.6, 0.7, "Text", size=50,
         bbox=dict(boxstyle="square",
                   ec=(1., 0.5, 0.5),
                   fc=(1., 0.8, 0.8),
                   )
         )
plt.title('Square Box')
plt.show()

# Rounded
plt.figure()
plt.text(0.55, 0.6, "Text", size=50,
         bbox=dict(boxstyle="round",
                   ec=(1., 0.5, 0.5),
                   fc=(1., 0.8, 0.8),
                   )
         )
plt.title('Round Box')
plt.show()


# Circle
plt.figure()
plt.text(0.55, 0.6, "Text", size=50,
         bbox=dict(boxstyle="circle",
                   ec=(1., 0.5, 0.5),
                   fc=(1., 0.8, 0.8),
                   )
         )
plt.title('Cirlce')
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.