如何在pyqtgraph中写\ latex字符?

时间:2015-05-26 13:33:42

标签: latex pyqtgraph

我使用pyqtgraph,我想在图上写一些公式。如何用乳胶合成酶写? matplolib有自己的TeX表达式解析器,但我找不到pyqtgraph的解决方案。

1 个答案:

答案 0 :(得分:1)

除格式之外的pyqtgraph中的标签和文本项。这是一个例子:

#!/usr/bin/python
# -*- coding: utf-8 -*-

from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
pg.setConfigOptions(antialias=True)
pg.setConfigOption('background', '#c7c7c7')
pg.setConfigOption('foreground', '#000000')
from pyqtgraph.ptime import time
app = QtGui.QApplication([])

p = pg.plot()
p.setLabel('bottom', '<font>The &Chi; Axi&Sigma;</font>', 
            units='<font>&Beta;-Juice</font>', **{'font-size':'20pt'})
p.getAxis('bottom').setPen(pg.mkPen(color='#000000', width=3))

p.setLabel('left', '<font>&mu;-cells</font>', units='<font>&mu;-meter</font>',
            color='#c4380d', **{'font-size':'20pt'})
p.getAxis('left').setPen(pg.mkPen(color='#c4380d', width=3))

p.showAxis('top')
p.getAxis('top').setPen(pg.mkPen(color='#77ab43', width=3))
p.setLabel('top', '<math>H(s) = &int;<sub>0</sub><sup>&infin;</sup> e<sup>-st</sup> h(t) dt</math>', color='#77ab43', **{'font-size':'30pt'})

p.showAxis('right')
p.setLabel('right', '<font>&Delta;</font> House', units="<font>&Omega;</font>",
            color='#025b94', **{'font-size':'20pt'})
p.getAxis('right').setPen(pg.mkPen(color='#025b94', width=3))

np.random.seed(1234)
data = 30*np.random.randn(10000)
mu = data.mean()
median = np.median(data)
sigma = data.std()

y,x = np.histogram(data, bins=50)

curve = p.plot(x=x,y=y, stepMode=True, pen=pg.mkPen(color="#636", width=2))

textstr = '<math><p>&mu;=%.2f</p><p>median=%.2f</p><p>&sigma;=%.2f</p></math>'%(mu, median, sigma)
text = pg.TextItem(html=textstr, border='#FFFFFF', fill="#ffffcc")
text.setParentItem(curve)
text.setPos(x.min(),y.max())

equation_string = '<math>H(s) = &int;<sub>0</sub><sup>&infin;</sup> e<sup>-st</sup> h(t) dt</math>'
eq_text = pg.TextItem(html=equation_string, border='#000000', fill='#ccffff')
eq_text.setParentItem(curve)
eq_text.setPos(-20, y.max()*0.5)

if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

这是输出的图像。 pyqtgraph_w_equations