I'm using pyqtgraph and I would like to write some formula on the graphs. How to write with the latex synthax? matplolib get its own TeX expression parser, but I can't find the solution for pyqtgraph.
The labels and text items in pyqtgraph except HTML formatting. Here is an example:
#!/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 Χ AxiΣ</font>',
units='<font>Β-Juice</font>', **{'font-size':'20pt'})
p.getAxis('bottom').setPen(pg.mkPen(color='#000000', width=3))
p.setLabel('left', '<font>μ-cells</font>', units='<font>μ-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) = ∫<sub>0</sub><sup>∞</sup> e<sup>-st</sup> h(t) dt</math>', color='#77ab43', **{'font-size':'30pt'})
p.showAxis('right')
p.setLabel('right', '<font>Δ</font> House', units="<font>Ω</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>μ=%.2f</p><p>median=%.2f</p><p>σ=%.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) = ∫<sub>0</sub><sup>∞</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_()
Here is an image of the output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With