test_usetex.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import pytest
  2. import platform
  3. import matplotlib as mpl
  4. from matplotlib.testing.decorators import check_figures_equal, image_comparison
  5. import matplotlib.pyplot as plt
  6. from matplotlib.ticker import EngFormatter
  7. @pytest.fixture(autouse=True) # All tests in this module use usetex.
  8. def usetex():
  9. if not mpl.checkdep_usetex(True):
  10. pytest.skip('Missing TeX of Ghostscript or dvipng')
  11. mpl.rcParams['text.usetex'] = True
  12. @image_comparison(baseline_images=['test_usetex'],
  13. extensions=['pdf', 'png'],
  14. tol={'aarch64': 2.868}.get(platform.machine(), 0.3))
  15. def test_usetex():
  16. fig = plt.figure()
  17. ax = fig.add_subplot(111)
  18. ax.text(0.1, 0.2,
  19. # the \LaTeX macro exercises character sizing and placement,
  20. # \left[ ... \right\} draw some variable-height characters,
  21. # \sqrt and \frac draw horizontal rules, \mathrm changes the font
  22. r'\LaTeX\ $\left[\int\limits_e^{2e}'
  23. r'\sqrt\frac{\log^3 x}{x}\,\mathrm{d}x \right\}$',
  24. fontsize=24)
  25. ax.set_xticks([])
  26. ax.set_yticks([])
  27. @check_figures_equal()
  28. def test_unicode_minus(fig_test, fig_ref):
  29. fig_test.text(.5, .5, "$-$")
  30. fig_ref.text(.5, .5, "\N{MINUS SIGN}")