Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pyqt5 math

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 :: How can one find the three largest values of an input array efficiently, namely without having to sort the input array? 
Python :: convert hex to decimal python 
Python :: decode base64 with python 
Python :: factorial recursion python 
Python :: python sftp put file 
Python :: google translate with python 
Python :: import counter python 
Python :: how to find how many processors you have with python 
Python :: force two decimal places python 
Python :: python get the key with the max or min value in a dictionary 
Python :: if you assign the result a void function to a variable in python, you get: 
Python :: python get filename without extension 
Python :: How to Create a Pie Chart in Seaborn 
Python :: python initialize dictionary with lists 
Python :: python truncate to integer 
Python :: number 1 
Python :: bar plot fix lenthgy labels matplot 
Python :: python iterate over object fields 
Python :: how to create your own programming language in python 
Python :: what is the purpose of the judiciary 
Python :: selenium python chrome path 
Python :: python version check 
Python :: pandas object to float 
Python :: all combination of params 
Python :: numpy set_printoptions 
Python :: how to clear a pickle file 
Python :: python finite difference approximation backward difference 
Python :: python tkinter quit button 
Python :: how to import tkinter in python 
Python :: resample python numpy 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =