Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

padding figures 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 :: correlation matrix in python 
Python :: pandas sample 
Python :: remove dict python 
Python :: flask documentation 
Python :: pytesseract.image_to 
Python :: how to check if a value is nan in python 
Python :: rotate 2 dimensional list python 
Python :: round down number python 
Python :: flask app.route 
Python :: how to use loop in python 
Python :: how to sort nested list in python 
Python :: what is python 
Python :: cross entropy 
Python :: if it is square python 
Python :: how to read a excel file in python 
Python :: inline for python 
Python :: pandas split groupby 
Python :: pandas remove duplicates 
Python :: count python 
Python :: step function 
Python :: python else syntax 
Python :: text detection from image using opencv python 
Python :: pandas add prefix to column names 
Python :: infinite for loop python 
Python :: função find python 
Python :: the requested resource was not found on this server. django 
Python :: put grid behind matplotlib 
Python :: python main template 
Python :: first n prime number finder in python 
Python :: why is there a lot of numbers in python 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =