Skip to main content

A single Python module, with no dependencies, producing an SVG image of a chart with one or more plotted lines

Project description

minilineplot

minilineplot.py is a single Python module, with no dependencies, producing an SVG image of a chart with one or more plotted lines.

The chart has a left vertical axis and a bottom horizontal axis, grid lines are possible,

Two classes are defined.

Line, containing x,y points which creates a line to be plotted

Axis which creates the axis, and to which Line objects can be added.

The Axis class has methods to create an svg string suitable for embedding in an html document it can also create an svg image, either as a bytes object, or saved to a file.

Line

Arguments

values a list of x,y tuples, x and y being integers or floats.

color an SVG color of the line, such as 'blue'.

stroke line width, 1 for a thin line.

label A label string for a key, if not given, the key will not be drawn

If the Axis 'xstrings' argument is set as strings along the x axis, for example months of the year, then values tuples should have x values as a percentage along the x axis (from 0 to 100).

Similarly if the Axis 'ystrings' argument is set as strings up the y axis, then values tuples should have y values as percentages.

Otherwise x,y values should be numeric values between the min and max Axis attributes.

color is an SVG color, using standard strings such as

Color Names: "red", "blue" etc.

Hex Codes: "#FF0000" for red.

RGB/RGBA: "rgb(255,0,0)" or "rgba(255,0,0,0.5)" (with opacity).

HSL/HSLA: "hsl(0,100%,50%)" or "hsla(0,100%,50%,0.5)" (hue, saturation, lightness, alpha)

Axis

Arguments

lines list of Line objects

fontsize default 24

imagewidth default 800

imageheight default 600

xstrings A list of strings used as the x axis values, use for text values such as months, etc.,

Alternatively, the above argument can be left empty and the following x axis values set instead.

xformat default string ".2f" Sets how the x axis numbers are formatted.

xmin default 0, the minimum x value

xmax default 10, the maximum x value

xintervals default 5, the interval spacing of values along the x axis, 5 would be five intervals and six values.

If any strings are set in xstrings, the above numbers are ignored

ystrings A list of strings used as the y axis values.

If any strings are set in ystrings line y values should all be percentages between 0 and 100.

yformat default string ".2f" Sets how the y axis numbers are formatted.

ymin default 0, the minimum y value

ymax default 10, the maximum y value

yintervals default 5, the interval spacing of values along the y axis, 5 would be five intervals and six values.

If any strings are set in ystrings, the above y axis values are ignored

title default "", A string printed at the top of the chart

description default "", A string printed at the bottom of the chart

verticalgrid default 1

0 is no vertical grid lines, 1 is a line for every x axis interval, 2 is a line for every second interval etc.,

horzontalgrid default 1

0 is no horizontal grid lines, 1 is a line for every y axis interval, 2 is a line for every second interval etc.,

The following colors are SVG colors, using standard strings

gridcol default "grey" Color of the chart grid

axiscol default "black" Color of axis, title and description

chartbackcol default "white" the background colour of the chart

backcol default "white" The background colour of the whole image

xformat and yformat are strings describing how numbers are printed, for example the string ".2f" gives a number to two decimal places.

If chart text starts overlapping, either decrease font size, or increase the image size while keeping fontsize the same.

All arguments are also object attributes, and can be changed as required.

Methods

to_string(xml_declaration = False)

Return a string SVG object. If xml_declaration is True, an xml tag will be included in the returned string which is usually required when creating an svg image file but not required if embedding the code directly into an html document,

to_bytes(xml_declaration = True)

Return a bytes SVG object.

to_file(filepath)

Save the plot to an svg image file

To install, either use Pypi, or simply copy minilineplot.py to your own project files, or just cut and paste the contents. The code is public domain.

Note, to keep things simple there is very little data validation, rubbish in = rubbish out.

Test image

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

minilineplot-0.0.3.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

minilineplot-0.0.3-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file minilineplot-0.0.3.tar.gz.

File metadata

  • Download URL: minilineplot-0.0.3.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.5

File hashes

Hashes for minilineplot-0.0.3.tar.gz
Algorithm Hash digest
SHA256 bfd7bebf68df277a9cc808d11c3cfd8e22c39bf31cd8594427af081ee6ac1f62
MD5 b1bb866c6a9c4803c632151f2174718e
BLAKE2b-256 5205a331ea9d2bf09793634818525ef37c6b18bba89a24c17deb2bcadf1fe77e

See more details on using hashes here.

File details

Details for the file minilineplot-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: minilineplot-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.5

File hashes

Hashes for minilineplot-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0e1bd16724903ac85f3b1f5663b2436bc473f773d4a245351f544c928f67b473
MD5 79f82497626d9625fc6c3b85c5d07a43
BLAKE2b-256 6b73aa0be18e2811124ee58375c85c49460f2a1db1dc5528e9e3468c58039a68

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