Skip to content

AlbertUnruh/gypt-matplotlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub License Python Version PyPI Version Downloads Code Style: black
pre-commit.ci Status Code QL PyTest
GitHub Issues GitHub PRs

gypt_matplotlib

A small addon for matplotlib that can be used for the GYPT.


Note

To install gypt-matplotlib, simply use pip.

pip install gypt_matplotlib

GYPT?

GYPT stands for German Young Physicists’ Tournament.

Further information can be found at gypt.org.

I'm a participant of the GYPT. Can I contribute?

Of course, you can. Even if you are just a former participant, you are welcome. In fact, everyone is welcome to contribute or ask for features!

Simply open an issue and say what you would like to do so that details can be clarified directly.

Where did you get the stylesheet?

It's available over here at the GYPT wiki.


How to use:

Applying GYPT-stylesheet

Just import the library. The stylesheet will be automatically applied.

import gypt_matplotlib as gypt

Creating plots with a.u. (arbitrary units)

You can use the context manager gypt.au_plot() to create plots where the concept and not the actual numbers are important.

import matplotlib.pyplot as plt
import gypt_matplotlib as gypt

with gypt.au_plot():
    plt.title("Demo of plot without numbers on X-/Y-Axis.")
    plt.show()

# or even more advanced:
with gypt.au_plot(), gypt.auto_save_and_show("path/to/file.png"):
    plt.title("Demo of plot without numbers on X-/Y-Axis.")

Using other diverse context managers

import matplotlib.pyplot as plt
import gypt_matplotlib as gypt

with gypt.auto_close():
    # This context manager automatically calls ``plt.close()``.
    # Saving and displaying have to be done manually!
    ...

with gypt.auto_show():
    # This context manager automatically calls ``plt.show()`` and ``plt.close()``.
    # It's incompatible with ``gypt.auto_save()``! Use ``gypt.auto_save_and_show()`` instead!
    ...

with gypt.auto_save("path/to/file.png"):
    # This context manager automatically calls ``plt.savefig()`` and ``plt.close()``.
    # It's incompatible with ``gypt.auto_show()``! Use ``gypt.auto_save_and_show()`` instead!
    ...

with gypt.auto_save_and_show("path/to/file.png"):
    # This context manager automatically calls ``plt.savefig()``, ``plt.show()`` and ``plt.close()``.
    ...

Using utils

This library offers multiple utilities which can be used. The following utils are included:

axes_label
import gypt_matplotlib as gypt

# with a unit
print(gypt.axes_label("v", unit=r"\frac{m}{s}"))  # $v$ in $\frac{m}{s}$

# with arbitrary unit
print(gypt.axes_label("I", is_au=True))  # $I$ in $\text{a.u.}$
tex
import gypt_matplotlib as gypt

print(gypt.tex(r"e^{i\pi}+1=0"))  # $e^{i\pi}+1=0$

About

A small addon for mpl that can be used for the GYPT.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •  

Languages