Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/SarahIaquinta/adaptative_uptake_of_NPs
13 April 2026, 01:16:16 UTC
  • Code
  • Branches (6)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/dependabot/pip/pillow-9.3.0
    • refs/heads/implement_PCE
    • refs/heads/investigate_PCE
    • refs/heads/main
    • refs/heads/pr_public_repo
    • refs/heads/release
    No releases to show
  • fbdbe95
  • /
  • np_uptake
  • /
  • figures
  • /
  • utils.py
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:02cde5d107bd9d7bb592450273dcbb44d2415d29
origin badgedirectory badge
swh:1:dir:13950f0565a43efdc87138ff8188a8c46329b116
origin badgerevision badge
swh:1:rev:27b6a958c5d57f02caec72211e0b6c83664e7e08
origin badgesnapshot badge
swh:1:snp:66144eb495e231b19013dc94fc62e65219436b22

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Tip revision: 27b6a958c5d57f02caec72211e0b6c83664e7e08 authored by Sarah Iaquinta on 24 June 2024, 06:06:49 UTC
Merge pull request #3 from anciaux/main
Tip revision: 27b6a95
utils.py
from io import BytesIO

import matplotlib.font_manager as font_manager
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image


class Fonts:
    """A class that defines the features of the fonts that will be used in the figures

    Attributes:
    ----------
    None

    Methods:
    -------
    serif(self):
        Introduces the serif font
    """

    def serif(self):
        """Introduces the serif font

        Parameters:
        ----------
        None

        Returns:
        -------
        font: font_manager object
            Serif font, with its features
        """

        font = font_manager.FontProperties(family="serif", weight="normal", style="normal", size=18)
        return font

    def serif_3horizontal(self):
        font = font_manager.FontProperties(family="serif", weight="normal", style="normal", size=40)
        return font

    def axis_legend_size(self):
        """Defines the size of the text in the axis legend of the figures

        Parameters:
        ----------
        None

        Returns:
        -------
        size_axis_legend: float
            Size of the text in the axis legend of the figures
        """

        size_axis_legend = 24
        return size_axis_legend

    def axis_label_size(self):
        """Defines the size of the text in the axis label of the figures

        Parameters:
        ----------
        None

        Returns:
        -------
        size_axis_label: float
            Size of the text in the axis label of the figures
        """
        size_axis_label = 25
        return size_axis_label

    def fig_title_size(self):
        """Defines the size of the title the figures

        Parameters:
        ----------
        None

        Returns:
        -------
        size_title: float
            Size of the text in the axis legend of the figures
        """

        size_title = 18
        return size_title


class SaveFigure:
    """A class which contains methods to export and save figures as image (.png or .tiff) files

    Attributes:
    ----------
    None

    Methods:
    -------
    save_as_png(self, fig, filename):
        Saves the figure as a .png file
    save_as_tiff(self, fig, filename):
        Saves the figure as a .tiff file
    """

    def save_as_png(self, fig, filename):
        """Saves the figure as a .png file

        Parameters:
        ----------
        fig: Figure object
            Figure that is to be saved as an image
        filename: str
            Name of the .png file under which the image must be saved

        Returns:
        -------
        None
        """

        png1 = BytesIO()
        fig.savefig(png1, format="png")
        png2 = Image.open(png1)
        png2.save(filename + ".png")

    def save_as_tiff(self, fig, filename):
        """Saves the figure as a .tiff file

        Parameters:
        ----------
        fig: Figure object
            Figure that is to be saved as an image
        filename: str
            Name of the .tiff file under which the image must be saved

        Returns:
        -------
        None
        """

        png1 = BytesIO()
        fig.savefig(png1, format="png")
        png2 = Image.open(png1)
        png2.save(filename + ".tiff")


class CreateFigure:
    """A class which contains the dimensions used to create the figures

    Attributes:
    ----------
    None

    Methods:
    -------
    rectangle_figure(self, pixels):
        Creates a rectangle figure of size 9x6
    square_figure(self, pixels):
        Creates a square figure of size 6x6
    square_figure_7(self, pixels):
        Creates a square figure of size 7x7
    """

    def rectangle_figure(self, pixels):
        """Creates a rectangle figure of size 9x6

        Parameters:
        ----------
        pixels: str
            Number of points per pixel in the figures Recommended: 360

        Returns:
        -------
        fig: Figure object
            Figure of dimension 9x6
        """

        fig = plt.figure(figsize=(9, 6), dpi=pixels, constrained_layout=True)
        return fig

    def square_figure(self, pixels):
        """Creates a square figure of size 6x6

        Parameters:
        ----------
        pixels: str
            Number of points per pixel in the figures Recommended: 360

        Returns:
        -------
        fig: Figure object
            Figure of dimension 6x6
        """

        fig = plt.figure(figsize=(6, 6), dpi=pixels, constrained_layout=True)
        return fig

    def square_figure_7(self, pixels):
        """Creates a square figure of size 7x7

        Parameters:
        ----------
        pixels: str
            Number of points per pixel in the figures Recommended: 360

        Returns:
        -------
        fig: Figure object
            Figure of dimension 7x7
        """

        fig = plt.figure(figsize=(7, 7), dpi=pixels, constrained_layout=True)
        return fig


class XTicks:
    """A class which defines the position of the labels that must appear in the abscises of the
    plots

    Attributes:
    ----------
    None

    Methods:
    -------
    energy_plots(self):
        Defines the position where the labels that must appear in the abscises of the plots of
        energy
    """

    def energy_plots(self):
        """Defines the position where the labels that must appear in the abscises of the plots of
        energy

        Parameters:
        ----------
        None

        Returns:
        -------
        xticks: list of floats
            list of the position of the labels of the x axis
        """

        xticks = [0, 0.2, 0.4, 0.6, 0.8, 1]
        return xticks


class XTickLabels:
    """A class which defines the labels in the abscises of the plots

    Attributes:
    ----------
    None

    Methods:
    -------
    energy_plots(self):
        Defines the labels that must appear in the abscises of the plots of energy
    """

    def energy_plots(self):
        """Defines the labels that must appear in the abscises of the plots of energy

        Parameters:
        ----------
        None

        Returns:
        -------
        xticks: list of strings
            list of the labels for the x axis
        """

        xticklabels = ["0", "0.2", "0.4", "0.6", "0.8", "1"]
        return xticklabels


def tikzplotlib_fix_ncols(obj):
    """
    workaround for matplotlib 3.6 renamed legend's _ncol to _ncols, which breaks tikzplotlib
    """
    if hasattr(obj, "_ncols"):
        obj._ncol = obj._ncols
    for child in obj.get_children():
        tikzplotlib_fix_ncols(child)
        

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API