Skip to content

Changed text.latex.preamble to avoid plotting bugs

Moritz Huebner requested to merge fix_matplotlib_latex_issue into master

There is currently an issue with using tex plotting style in bilby. It is especially frustrating since the issue arises even if bilby is merely imported but not used. I was not able to figure out the root of the issue, but it seems to causes issues like the following:

RuntimeError: latex was not able to process the following string:
b'$\\\\times\\\\mathdefault{10^{-3}}\\\\mathdefault{}$

This can be reproduced by running the script below. Note that bilby is imported but unused.

import bilby
import matplotlib
import matplotlib.pyplot as plt

matplotlib.rc('text', usetex=True)
plt.plot([1e-3, 2e-3, 3e-3], [1e-3, 2e-3, 3e-3])
plt.savefig('testing.png')
plt.show()

I resolved the issue by defining the \mathdefault command in the outermost __init__.py, using the same syntax that is used in the bilby.core.utils.latex_plot_format wrapper.

I am aware that there are a few other people that had similar issues, so it would be good to test if this consistently resolves the issue. @nikhil.sarin @matthew-pitkin

Merge request reports