Skip to main content

Compose raster and vector images to publication-ready figures for scientific journals

Project description

svgsubfig

PyPI - Version GitHub License Code style - black

A python package for swift arrangement of raster images and vector graphics into a single figure based on SVG.

This package is focussed on the preparation of high quality figures that consist of several subimages, both vector and raster graphics, for publication in scientific journals. A label is inserted below each subimage, e.g. (a), (b), ...

Font family, size and gaps can be adjusted based on a JSON configuration. An example figure created with svgsubfig could look like this:

example figure created with svgsubfig

Basic usage

Installation

svgsubfig can be installed using pip:

pip install svgsubfig

Configuration

Create a JSON configuration file with the following structure, use relative filenames for the individual (sub-)images (the directory of the config file acts as base directory).

{
    "gap-between": 5,
    "gap-label": 3,
    "width": 150,
    "font-size": 9,
    "font-family": "Arial, Helvetica, sans-serif",
    "images": [
        "img/dog.jpeg",
        "img/population.svg"
    ],
    "description": [
        "A dog.",
        "The dogs population."
    ]
}

Following keys are available for the config file:

  • description: Text to be added after each label.
  • font-family: Typeface used in the SVG file for text.
  • font-size: Size of the labeling of the images in pt.
  • gab-between: Spacing between the subimages in mm.
  • gap-label: Spacing between labels and lower boundary of the images in mm.
  • images: Array of file paths of the images to include into the figure.
  • index-offset: Offset of the first subimage index, e.g. if index-offset = 3, the first label will be (d)
  • width: Width of the figure in mm.

To use automatic conversion of the created SVG figure file into PDF and PNG file formats, Inkscape needs to be installed and accessible on PATH.

Figure composition

To create the final figure using the JSON configuration, a small svgsubfig command line utility can be used, but also scripting is possible.

Command line utility

To use the svgsubfig module to create the final figure file, use following command in your terminal:

python -m svgsubfig [--noconvert] CONFIG_PATH

Replace CONFIG_PATH with the path of the JSON config file. Option --noconvert prevents conversion of the created SVG into PDF and PNG with Inkscape, which is useful in case Inkscape is not installed, or manual edits on the created SVG file are necessary.

Script

import svgsubfig.utility as util

from svgsubfig import SVGSubFigure
from pathlib import Path

pth_config = Path("figure.json")
pth_svg = pth_config.with_suffix(".svg")

fig = SVGSubFigure.from_json(pth_config)
fig.save(pth_svg)

util.convert_svg(pth_svg)

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

svgsubfig-0.2.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

svgsubfig-0.2.2-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file svgsubfig-0.2.2.tar.gz.

File metadata

  • Download URL: svgsubfig-0.2.2.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.6 Windows/11

File hashes

Hashes for svgsubfig-0.2.2.tar.gz
Algorithm Hash digest
SHA256 a662ad103f4c35ace20edabe459817387b24a45ec001d45e7bbfe271eb8a5499
MD5 119e134a67b14026080b0c9890791644
BLAKE2b-256 d5033959e4f99ddff4bc99c7a54ad5d25cc98b893b8bfb71a184575b00909016

See more details on using hashes here.

File details

Details for the file svgsubfig-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: svgsubfig-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.6 Windows/11

File hashes

Hashes for svgsubfig-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 29100fa8a217a0424dff19d106bb6c4832dbe1dd003951012321729f0d9066d5
MD5 676fbfc10ceef8e1d8b6960e3518793e
BLAKE2b-256 034925a6e9bed7faf35109392d50bc121321836dd4dc1702068211cd3800ebd8

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