monochrome_visualisation.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. __author__ = "Christian Heider Nielsen"
  4. __doc__ = r"""
  5. on ubuntu ensure to run:
  6. sudo apt install dvipng texlive-latex-extra texlive-fonts-recommended
  7. Created on 24-02-2021
  8. """
  9. import numpy
  10. from matplotlib import pyplot
  11. from matplotlib.pyplot import legend
  12. from draugr.visualisation import (
  13. MonoChromeStyleSession,
  14. auto_post_hatch,
  15. monochrome_hatch_cycler,
  16. simple_hatch_cycler,
  17. use_monochrome_style,
  18. )
  19. def line_plot() -> None:
  20. """
  21. :rtype: None
  22. """
  23. with MonoChromeStyleSession():
  24. fig, ax = pyplot.subplots(1, 1)
  25. for x in range(3):
  26. import numpy
  27. ax.plot(numpy.random.rand(10), label=f"{x}")
  28. from matplotlib.pyplot import legend
  29. legend()
  30. pyplot.show()
  31. def bar_plot() -> None:
  32. """
  33. :rtype: None
  34. """
  35. use_monochrome_style(prop_cycler=monochrome_hatch_cycler)
  36. fig, ax = pyplot.subplots(1, 1)
  37. for x in range(3):
  38. ax.bar(x, numpy.random.randint(2, 10), label=f"{x}")
  39. legend()
  40. from draugr.visualisation.matplotlib_utilities.quirks import fix_edge_gridlines
  41. fix_edge_gridlines(ax)
  42. auto_post_hatch(ax, simple_hatch_cycler)
  43. pyplot.show()
  44. if __name__ == "__main__":
  45. line_plot()
  46. bar_plot()