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 :: spark df to pandas df 
Python :: random python range 
Python :: python split by first match 
Python :: boids algorithm 
Python :: remove multiple elements from a list in python 
Python :: get basename without extension python 
Python :: python text reverse 
Python :: logging 
Python :: pandas read to a csv file 
Python :: find max length of list of list python 
Python :: python program to print the fibonacci sequence 
Python :: all() python 
Python :: automate boring stuff with python 
Python :: python dict remove duplicates where items are not the same 
Python :: python regular expression 
Python :: python - how many letters are capital in a string 
Python :: split stringg to columns python 
Python :: Python "for in" loop to print the last item in the list 
Python :: pyautogui locatecenteronscreen mac fix 
Python :: how to select li element in selenium python 
Python :: pandas where retuning NaN 
Python :: python file write 
Python :: change xticks python 
Python :: how to check encoding of csv 
Python :: how to do randon in python 
Python :: python if statement 
Python :: fillna not work 
Python :: pygame.events 
Python :: bar plot group by pandas 
Python :: python logo png 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =