Skip to main content

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

Project description

svgsubfig

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

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"
    ]
}

Following keys are available for the config file:

  • 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.1.0.tar.gz (5.6 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.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for svgsubfig-0.1.0.tar.gz
Algorithm Hash digest
SHA256 77a9a49ee3840fbe6d03822fa547d7d7193c4a1858c84988e99ffe9e663ff6e7
MD5 7fe8aa59d8ef0954dd93949e8ca2922c
BLAKE2b-256 d992fb033780f9c0c83d5ba6660a186b67e323fdbb39734cd5c89a048cafb08e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for svgsubfig-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1fc4bfe0d9d68a4b4ce8c3f01fbea0650a9f83d8b38aacac563b3ae7695600cc
MD5 757ef476375d67e6b40ff19fcecc67e9
BLAKE2b-256 25f173642840841b17218024527bb39a16b4405243787ee2b4d5b5f2b05bcfcd

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