pastamarkers

Data should always be carefully and thoughtfully presented. Although this rule seems quite general, it is backed by a very logical rationale. Plots should serve as a direct and clear way to communicate a message. And therefore it is important to select the most effective settings to convey this message. There are right and wrong choices to make when it comes to data representation. And pastamarkers is a delightfully good one.


pastamarkers are markers not only fully compatible with the Python matplotlib library, but also they come in pasta form. As discussed in the paper titled pastamarkers: astrophysical data visualization with pasta-like markers published on March 2024 (arXiv.2403.20314), their aim is to facilitate the visualization of astrophysical data.


Let's test it on a concrete example.


From the paper titled Observation of a new particle in the search for the Standard Model Higgs boson with the ATLAS detector at the LHC published in July 2012 (j.physletb.2012.08.020), one can see a plot related to the (incredible) discovery of the Higgs boson, which looks like this:

Higgs boson, original plot

For the sake of this example, the original plot was slightly cropped, but the result, representing a real milestone in particle physics, is unaltered.


And I was wondering what happens if one would plot the same data, but with pastamarkers. To make this exercise even more interesting, I tried to copy as much as possible the style of the plot, using only matplotlib. The result, as well as the code, are presented below:

Higgs boson, transformed plot
     
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
from pastamarkers import markers

rc = {"xtick.direction" : "in", "ytick.direction" : "in",
      "xtick.major.size" : 5, "ytick.major.size" : 5,}
with plt.rc_context(rc):
    fig, ax = plt.subplots(figsize=(8, 4.5))

    plt.scatter(x_data, y_data, 
                marker=markers.farfalle, 
                s=300, linewidth=0.2, 
                color="k", 
                label=r"$\rm{Data}$", 
                zorder=10)
    plt.plot(x_peak, y_peak, 
                linestyle="solid", 
                linewidth=2, 
                color="red", 
                label=r"$\rm{Sig}\rm{+}\rm{Bkg~Fit~(} \rm{m}_H=126.5~\rm{GeV)}$")
    plt.plot(x_cont, y_cont, 
                linestyle="--", 
                linewidth=2, 
                color="red", 
                label=r"$\rm{Bkg~(4th~order~polynomial)}$")

    ax.yaxis.set_minor_locator(MultipleLocator(100))
    ax.xaxis.set_minor_locator(MultipleLocator(2))

    font_size = 20
    plt.xlabel(r"$\rm{m}_{\gamma\gamma} ~\rm{[GeV]}$ ", 
                fontsize=font_size-4, 
                horizontalalignment="right", 
                x=1.0)
    plt.ylabel(r"$\rm{Events~/~2~GeV}$", 
                fontsize=font_size-4, 
                horizontalalignment="right", 
                y=1.0)
    plt.xticks(fontsize=font_size-4)
    plt.yticks(fontsize=font_size-4)

    ax.set_xlim([100, 160])
    ax.set_ylim([4, 3999])

    plt.legend(loc="upper right", 
                fontsize=font_size-5, 
                framealpha=0, 
                edgecolor="white", 
                fancybox=False)

    ax.xaxis.set_ticks_position("both")
    ax.yaxis.set_ticks_position("both")
    ax.tick_params("y", 
                    length=20, 
                    width=2, 
                    which="major")
    ax.tick_params("y", 
                    length=10, 
                    width=1, 
                    which="minor")


    plt.text(104, 1300, 
                r"$\sqrt{s} = 7~\rm{TeV},\int L \rm{d}t = 4.8 \rm{fb}^{-1}$", 
                fontsize=font_size-5)
    plt.text(104, 900, 
                r"$\sqrt{s} = 8~\rm{TeV},\int L \rm{d}t = 5.9 \rm{fb}^{-1}$", 
                fontsize=font_size-5)
    plt.text(130, 400, 
                r"$\rm{H} \to \gamma \gamma$", 
                fontsize=font_size-3)

    plt.show()
    

You can notice that x_data, y_data, x_peak, y_peak, x_cont, and y_cont are not given in the code, simply because their values are available on the plot itself.


In that very specific example, I used my favorite pasta type, which is farfalle. But many other possibilities are available. I highly recommend you to check them either in their paper, or directly on their Github repository.


Is there a moral to that story? Not really. I just really liked how these types of pastas look like, and also wanted an excuse to show a brilliant high-energy physics result.