Python | Text Box in Plane Figure

In this tutorial, we are going to learn how to draw a text box in a plane figure i.e. without any axis?
Submitted by Anuj Singh, on August 16, 2020

It is rarely used but again, in some cases where we need only to show a text box, we can do so by using the function matplotlib.pyplot.axis(Flase).

Illustrations:

Python | Text Box in Plane Figure (1)

Python | Text Box in Plane Figure (2)

Python | Text Box in Plane Figure (3)

Python code for text box in plane figure

import matplotlib.pyplot as plt

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

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


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