Skip to main content

Object-oriented, two-stage PDF figure generation library for Python.

Project description

Fiject

Object-oriented, two-stage PDF figure generators in Python.

Gives an answer to "How can I change the look of a figure without re-computing its data?" which isn't possible in matplotlib nor seaborn.

Features

  • Two-stage figure generation:
    • Addition stage: Incrementally add data to figure objects, rather than needing to do it all at once along with visual parameters. Data caching allows skipping this step when a figure needs to be reformatted but not recomputed.
    • Commit stage: Format the data stored in a figure object, with a simple interface that hides the complexities of matplotlib and seaborn.
  • Supported figure types:
    • LineGraph: points connected by lines.
    • Bars: bar plot on a categorical axis.
    • MultiHistogram: one or more histograms on the same numerical axis. Can also be committed to box plots.
    • ScatterPlot: unconnected points.
    • Table: LaTeX tables with hierarchical rows and hierarchical columns, column stylisation (e.g. rounding, min/max bolding, ...) and borders where you need them.

Example

Let's say you have a machine learning project where a classifier called model is trained and then evaluated on precision (Pr), recall (Re) and F1 score, for 5 different values of a hyperparameter h. You would do your experiments as follows:

from fiject import LineGraph, CacheMode

g = LineGraph("project-results", caching=CacheMode.IF_MISSING)
if g.needs_computation:
    h_values = [0.1, 0.25, 0.5, 0.7, 1.0]
    for h in h_values:
        # ...
        # model.trainModel(h)  # Takes hours to compute. We don't want to repeat it just to reformat the graph!
        # pr, re, f1 = model.evaluateYourModel()
        # ...
        g.add("Pr",    h, pr)
        g.add("Re",    h, re)
        g.add("$F_1$", h, f1)
              
g.commit(aspect_ratio=(4,3), y_lims=(0, 100), x_tickspacing=0.1, y_tickspacing=10,
         x_label="Hyperparameter value", y_label="Binary classification performance [\\%]")

A PDF project-results_0.pdf will appear, and the data will be cached in a file project-results_0.json.

Notice that the CacheMode along with the check if g.needs_computation will ensure that you don't have to redo your computation if you don't like the way your figure came out the first time. You can just change the parameters to g.commit() and re-run the same code to get a new PDF project-results_1.pdf instantly.

Installation

You can install fiject as any other package, or as a developer if you want to tinker with the source yourself.

Normal install

Open a terminal and run:

pip install git+https://github.com/bauwenst/fiject.git

Developer install

Open a terminal and, instead of the above, run:

git clone https://github.com/bauwenst/fiject.git
cd fiject
pip install -e .

The last command will detect the pyproject.toml file (pip install), look for the fiject/__init__.py file in the current directory (.), and put a symlink to this folder in Python's site-packages folder (-e). This means that when you import fiject, it is imported from the current folder and hence any changes you make here are applied immediately.

Credit

This package was developed over the span of multiple years (2021-2023) and across multiple research papers at university. If you produce figures for your own reports with this package, please be a kind human and acknowledge my work by crediting this repository in a footnote. For example, in LaTeX:

\footnote{All figures were made using Fiject (\url{https://github.com/bauwenst/fiject}), 
          a Python package by ir.\ Thomas Bauwens.}

Showcase

A collage of all the figures I have drawn with this code across many university projects.

Line graphs



Histograms

Bar plots

Scatterplots

Tables

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fiject-2024.1.1.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fiject-2024.1.1-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

Details for the file fiject-2024.1.1.tar.gz.

File metadata

  • Download URL: fiject-2024.1.1.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.13.12 HTTPX/0.28.1

File hashes

Hashes for fiject-2024.1.1.tar.gz
Algorithm Hash digest
SHA256 55e09c6161b23a5d3e78c9d6233d2574ed382b620c9673a66c9719338583d3bf
MD5 8d4a78dfd8d0f3dead6195f8fa192038
BLAKE2b-256 ab7331ea0fddc416de0567785258f00f3dd75683048d55f395b2a9a98037b81a

See more details on using hashes here.

File details

Details for the file fiject-2024.1.1-py3-none-any.whl.

File metadata

  • Download URL: fiject-2024.1.1-py3-none-any.whl
  • Upload date:
  • Size: 33.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.13.12 HTTPX/0.28.1

File hashes

Hashes for fiject-2024.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6d782717f786f070d63183e4bcd84da4adcf7620a68ecfe47794e24747656088
MD5 07bda0ddcbc466a1e187dd63ecf766cb
BLAKE2b-256 f2f83cea2796983b71751d24225c471da60188a9525dce7c2f5a6050612d0b26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page