monochrome_visualisation.py 1.1 KB

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