Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

bounding box python

Bounding boxes are axis-aligned rectangles. They are the simplest closed shape type in 
planar, represented by two points containing the minimum and maximum coordinates for 
each axis.
Comment

bounding box in python

import matplotlib
matplotlib.rc('text',usetex=True)
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import numpy as np

text = 'egin{tabular}{|c|c|}hline1&2\hline3&4\hlineend{tabular}'

fig, ax = plt.subplots(1)

img = ax.imshow(np.zeros((10,10)), cmap=plt.cm.gray)
txt = ax.text( 4.5,
          4.5,
          text,
          fontsize=24,
          ha='center',
          va='center',
          bbox=dict(alpha=0))

fig.canvas.draw()
bbox = txt.get_bbox_patch()
xmin = bbox.get_window_extent().xmin
xmax = bbox.get_window_extent().xmax
ymin = bbox.get_window_extent().ymin
ymax = bbox.get_window_extent().ymax

xmin, ymin = fig.transFigure.inverted().transform((xmin, ymin))
xmax, ymax = fig.transFigure.inverted().transform((xmax, ymax))

dx = xmax-xmin
dy = ymax-ymin

# The bounding box vals can be tweaked manually here.
rect = Rectangle((xmin-0.02,ymin-0.01), dx+0.04, dy+0.05, fc='w', transform=fig.transFigure)

ax.add_patch(rect)
fig.canvas.draw()
ax.axis('off')
plt.savefig('ok.png',bbox_inches='tight')




Comment

PREVIOUS NEXT
Code Example
Python :: fizz buzz fizzbuzz python game 
Python :: bokeh bar chart 
Python :: if else usage python 
Python :: python how to draw a rectangle 
Python :: for range python 
Python :: divide list into equal parts python 
Python :: youtube bot python 
Python :: rename folder python 
Python :: python get an online file 
Python :: sum of the number in a list in python 
Python :: * pattern program in python 
Python :: sklearn.metrics accuracy_score 
Python :: hide console in python build 
Python :: global python 
Python :: Python How To Convert Text to Speech 
Python :: positive and negative number in python 
Python :: tuple unpacking 
Python :: generator comprehension python 
Python :: vstack numpy 
Python :: how to save python variables locally 
Python :: python if syntax 
Python :: pandas change column order 
Python :: How to code a simple rock, paper, scissors game on Python 
Python :: numpy sign method 
Python :: use chrome console in selenium 
Python :: how to add items in list in python at specific position 
Python :: python range function examples 
Python :: python how do index all odd numbers in a list 
Python :: string to list of characters python 
Python :: python excel sheet 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =