Skip to main content

Mathematics oriented SVG creation

Project description

mathsvg

A Python library to draw mathematical objects. Create figures and diagrams and save them as SVG files.

The complete documentation is available at: https://mathsvg.readthedocs.io. The sources are hosted on GitHub: https://github.com/alexn11/mathsvg.

Programs such as Inkscape are great for creating vector graphics. But Inkscape is made more for designer rather than for mathematicians. The process of doing mathematical diagrams and illustrations using Inkscape can sometimes be quite frustrating. Making a python script to produce the content of an SVG file can be a faster solution.

The role of mathsvg is to help with the process of producing your own SVG diagrams using Python scripts. For that purpose a class SvgImage is defined which contains many usefull routines that simplify the creation of mathematical figures with precise descriptions.

Once the mathsvg package and all its dependencies are installed it can be used as a normal Python package.

Here is an example for the creation of a very simple image:

import mathsvg
image = mathsvg . SvgImage (rescaling = 100, shift = [ 1, 1 ], view_box = (200, 200))
image . draw_circle ([0, 0], 1.1)
image . save ("simple-example.svg")

The above program does the following.

After importing the package mathsvg, a SvgImage object is created. The parameters of the constructors are a rescaling factor, a shift vector and the view box. The rescaling factor and the shift vector are used to convert mathematical object coordinates into pixel coordinates in the SVG. The shift vector corresponds to a translation which is first applied to the coordinates. After this translation both coordinates are multiplied by the rescaling factor. Those are optional parameters and the respective default are 1 and [0, 0]. As for the view box, this means that only the points with x and y coordinates between -1 and 1 will be on the canvas (the y axis is automatically flipped over, ignore the content of this parenthesis if you don't know why this should be).

A circle with center (0, 0) and radius 1.1 is drawn using the default drawing options (black solid stroke). Some points of the circle won't appear in the image since they are outside the canvas.

Finally the file is saved with the name "simple-example.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

mathsvg-0.2.0.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

mathsvg-0.2.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file mathsvg-0.2.0.tar.gz.

File metadata

  • Download URL: mathsvg-0.2.0.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for mathsvg-0.2.0.tar.gz
Algorithm Hash digest
SHA256 134b075bcf3c6184e81dd7ae01a0679d2776779be62a3a3ed11d9e4aaad0f171
MD5 e2ab56d02c6f82cd341e0ed8212d063d
BLAKE2b-256 abebf5327e8f23f099d817228b91e8b36c5cb7252e54f45fdb7c822e950c76eb

See more details on using hashes here.

File details

Details for the file mathsvg-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mathsvg-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for mathsvg-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59db3693432d57af88301e02f73278a7eddef844c97e906bfc058f52071690a2
MD5 74a04a1a5ccb6f05661efe03265e0e2d
BLAKE2b-256 5db301d51908a33f74c89c3929da72703e24c5ac8fe0e779dd5ac9638978d31f

See more details on using hashes here.

Supported by

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