Search code examples
pythondictionarysymbols

Python dictionary with math symbols


I want to make a dictionary in Python, but with math symbols (because then i want to plot that with the symbols).

So, i have something like this:

    dict_particles = {1: "Gamma", 
              2: "e+",
             -2: "e-",
              3: "mu+", 
             -3: "mu-",
              4: "pi0",
             -4: "pi+",
                  etc...}

Instead of the name "Gamma", for example, I want the symbol of the greek letter. Also i want to put super and subscripts to them.

Is it possible?


Solution

  • If you are using matplotlib.pyplot, you could simply use the syntax mentioned here:

    text = r'$\alpha > \beta$'
    

    Which matplotlib.pyplot will translate into pretty greek symbols, for example with

    plt.title(text)
    

    For your concrete example:

    dict_particles = {1: r"\Gamma", 
                      2: r"\epsilon+", ...}