Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pyqt latex

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 latex 
Python :: how to change the datatype of a row in pandas 
Python :: add empty row to pandas dataframe 
Python :: how to draw polygon in tkinter 
Python :: all column except pandas 
Python :: static dirs django 
Python :: schedule asyncio python 
Python :: python search string for word 
Python :: how to change the column order in pandas dataframe 
Python :: remove turtle 
Python :: trump 
Python :: python color text console 
Python :: python delete header row 
Python :: list count frequency python 
Python :: count unique values in pandas column 
Python :: get adjacent cells in grid 
Python :: python ls 
Python :: download kaggle dataset in colab 
Python :: all characters python 
Python :: how to iterate through a text file in python 
Python :: python timedelta 
Python :: how to find the version of python command linw 
Python :: panda dataframe read csv change string to float 
Python :: parameter grid 
Python :: Update label text after pressing a button in Tkinter 
Python :: python get files in directory 
Python :: pandas reorder columns 
Python :: pandas find basic statistics on column 
Python :: python range backward 
Python :: python count distinct letters 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =