Skip to content

simongravelle/pyplot-perso

Repository files navigation

DOI License: GPL v3

Matplotlib Pyplot functions

My own Python class for making Pyplot figures compatible with Latex documents. These functions are used in my most recent publications, as well as in:

Examples

Simple bi-panel figure

illustration

illustration

The Python code to generate the figure:

    # Initialise figure
    myplt = PltTools()
    myplt.prepare_figure(fig_size = (18,12), dark_mode = dark_mode,
                         transparency = True, n_colone = 2)
    # Panel 1
    myplt.add_panel(panel_position = [0, 0])
    myplt.add_plot(x = x1, y = y1/2, marker = "o", data_color = 2,
                   markersize = 6, data_label = r"$\textrm{data}~\alpha$")
    myplt.add_plot(x = x3, y = y3, marker = "o", data_color = 0, markersize = 10,
                   data_label = r"$\textrm{data}~\beta$")
    myplt.add_plot(x = x2, y = y2, marker = "-", data_color = "autogray",
                   data_label = r"$\textrm{linear fit}$")
    myplt.complete_panel(xlabel = r"$x ~ \textrm{[\AA{}]}$", ylabel = r"$t ~ \textrm{[ps]}$",
                         panel_title = r"$\textrm{Time vs distance}$", xpad = 10)
    myplt.set_boundaries(y_boundaries = (0, 5))
    # Panel 2
    myplt.add_panel(type = 'loglog', panel_position = [0, 1])
    myplt.add_plot(x = x4, y = y4, marker = "o", data_color = 0,
                   markersize = 16)
    myplt.add_plot(x = x5, y = y5, marker = "p", data_color = 0,
                   markersize = 16)
    myplt.add_plot(x = x6, y = y6, marker = "^", data_color = 0,
                   markersize = 16)
    myplt.complete_panel(xlabel = r"$E ~ \textrm{[J]}$", ylabel = r"$N_\textrm{p} ~ [0]$",
                         panel_title = r"$\textrm{Population size vs energy}$", xpad = 10)
    myplt.set_boundaries(x_boundaries = (0.01, 1000), y_boundaries = (0.01, 1000))
    # Finish figure
    myplt.add_subplotlabels(type_label_panel = "a")
    myplt.save_figure(filename = "bi-panel", saving_path = 'examples/', show = False)

See also the examples notebook.

Light mode vs dark mode

  • For web integration, use either dark or light mode with a transparent background, as done for instance in lammps tutorials.
  • For scientific publication, use the light mode without transparent background.