Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pyqt tex

import sys
import matplotlib as mpl
from matplotlib.backends.backend_agg import FigureCanvasAgg
from PySide import QtGui, QtCore

def mathTex_to_QPixmap(mathTex, fs):

    #---- set up a mpl figure instance ----

    fig = mpl.figure.Figure()
    fig.patch.set_facecolor('none')
    fig.set_canvas(FigureCanvasAgg(fig))
    renderer = fig.canvas.get_renderer()

    #---- plot the mathTex expression ----

    ax = fig.add_axes([0, 0, 1, 1])
    ax.axis('off')
    ax.patch.set_facecolor('none')
    t = ax.text(0, 0, mathTex, ha='left', va='bottom', fontsize=fs)

    #---- fit figure size to text artist ----

    fwidth, fheight = fig.get_size_inches()
    fig_bbox = fig.get_window_extent(renderer)

    text_bbox = t.get_window_extent(renderer)

    tight_fwidth = text_bbox.width * fwidth / fig_bbox.width
    tight_fheight = text_bbox.height * fheight / fig_bbox.height

    fig.set_size_inches(tight_fwidth, tight_fheight)

    #---- convert mpl figure to QPixmap ----

    buf, size = fig.canvas.print_to_buffer()
    qimage = QtGui.QImage.rgbSwapped(QtGui.QImage(buf, size[0], size[1],
                                                  QtGui.QImage.Format_ARGB32))
    qpixmap = QtGui.QPixmap(qimage)

    return qpixmap
Comment

PREVIOUS NEXT
Code Example
Python :: pyqt5 pylatex 
Python :: python get name of tkinter frame 
Python :: flask make static directory 
Python :: pythondatetime cheatsheet 
Python :: display entire row pandas 
Python :: python rickroll code 
Python :: python number guessing game 
Python :: system commands in python windwos 
Python :: how to move a column in pandas dataframe 
Python :: pyhton turtle kill 
Python :: how to get the live website html in python 
Python :: check if user has manage messages discord.py 
Python :: pandas change frequency of datetimeindex 
Python :: A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable. 
Python :: matplotlib axes labels 
Python :: how to make square shape python 
Python :: how to increase size of graph in jupyter 
Python :: colab kaggle dataset 
Python :: python code to find the length of string in a list 
Python :: find null value for a particular column in dataframe 
Python :: tqdm parallel 
Python :: python check version 
Python :: how to convert a pandas series from int to float in python 
Python :: generate all parameters combination python 
Python :: how to change the color of command prompt in python 
Python :: how to convert png to pdf with python 
Python :: trimming spaces in string python 
Python :: python datetime to timestamp 
Python :: add font to the label in window tkinter 
Python :: how to download excel file from s3 using python 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =