一千萬個為什麽

搜索

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(). Seems matplotplot has TeX parsers, but I can't figure out how to use them...

謝謝。

最佳答案

作為變種:

    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()

轉載註明原文: matplotlib - 在Qt表單上寫TeX