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.1.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.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: svgsubfig-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 310d3cffc100aab6313b49b7a1c2582db60c82b49d96c9f7f478520105720026
MD5 815fae82adbd52f4c3115807d572ff40
BLAKE2b-256 faa893be682779aaa0226d26a1e4b75daa720ec92411c4affa80c5cf7288f65f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: svgsubfig-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 02586e46bb49eeea1986d5a59292f8f60f37b2b76bd6bfd1078d9a1de54959ee
MD5 ccb05899b14377c9b1a4093022ad5f7b
BLAKE2b-256 5e95ab8b3eb8928b2f48349edd895d15d65acd6384876c10201fa5e25c532878

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