Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to use pyplot

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 :: bounding box in matplotlib 
Python :: fizz buzz fizzbuzz python game 
Python :: pandas sample 
Python :: install python 3.7 
Python :: graph outlier detection 
Python :: how to make a screen in pygame 
Python :: str in python 
Python :: runserver coomand in django 
Python :: how to access variable of one function in another function in python 
Python :: sum function python 
Python :: games made with python 
Python :: print dataframe name python 
Python :: import os python 
Python :: Getting the data type 
Python :: slider python 
Python :: python dictionary accessing an element 
Python :: Count upper case characters in a string 
Python :: for en python 
Python :: self.variable 
Python :: any and all in python3 
Python :: raspbian run a python script at startup 
Python :: python true and false 
Python :: how to make a calcukatir in python 
Python :: email validation using django 
Python :: python dataframe find no of true 
Python :: python for print 
Python :: get source selenium python 
Python :: first non repeating charcter in string ython 
Python :: how to remove text in pygame 
Python :: pandas mask multiple condition 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =