Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib - write TeX on Qt form

Tags:

matplotlib

qt

tex

I'd like to add some TeX text to my Qt form, like label - just text, no graph, no lines, no borders, just TeX. I thought something like this: render TeX to bitmap and then place that bitmap on form, e.g. into QLabel. Or even better - use some backend, add it to form and use something tex_label.print_tex(<tex code>). Seems matplotplot has TeX parsers, but I can't figure out how to use them...

Thanks.

like image 456
demalexx Avatar asked Apr 18 '10 07:04

demalexx


Video Answer


1 Answers

As a variant:

    from matplotlib.figure import Figure
    from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg

    # Get window background color
    bg = self.palette().window().color()
    cl = (bg.redF(), bg.greenF(), bg.blueF())

    # Create figure, using window bg color
    self.fig = Figure(edgecolor=cl, facecolor=cl)

    # Add FigureCanvasQTAgg widget to form
    self.canvas = FigureCanvasQTAgg(self.fig)        
    self.tex_label_placeholder.layout().addWidget(self.canvas)

    # Clear figure
    self.fig.clear()

    # Set figure title
    self.fig.suptitle('$TeX$',
                      x=0.0, y=0.5, 
                      horizontalalignment='left',
                      verticalalignment='center')
    self.canvas.draw()
like image 192
demalexx Avatar answered Nov 16 '22 02:11

demalexx