Skip to main content

Plotting tools for complex-valued functions

Project description

cplot

Plot complex-valued functions with style.

CircleCI codecov Code style: black PyPi Version GitHub stars

cplot helps plotting complex-valued functions in a visually appealing manner. The general idea is to map the absolute value to lightness and the complex argument (the "angle") to the chroma of the representing color. This follows the domain coloring approach, also described by John D. Cook and Elias Wegert in the book Visual Complex Functions (with some tweaks).

Install with

pip3 install cplot --user

and use as

import cplot
import numpy

cplot.show(numpy.tan, -5, +5, -5, +5, 100, 100)

cplot.save_fig("out.png", numpy.tan, -5, +5, -5, +5, 100, 100)
cplot.save_img("out.png", numpy.tan, -5, +5, -5, +5, 100, 100)

# There is a tripcolor function as well for triangulated 2D domains
# cplot.tripcolor(triang, z)

# The function get_srgb1 returns the SRGB1 triple for every complex input value.
# (Accepts arrays, too.)
z = 2 + 5j
val = cplot.get_srgb1(z)

All functions have the optional arguments (with their default values)

alpha=1  # >= 0
colorspace="cam16"  # "cielab", "hsl"
  • alpha can be used to adjust the use of colors. A value less than 1 adds more color which can help isolating the roots and poles (which are still black and white, respectively). alpha=0 ignores the magnitude of f(z) completely.

  • colorspace can be set to hsl to get the common fully saturated, vibrant colors. This is usually a bad idea since it creates artifacts which are not related with the underlying data. From Wikipedia:

    Since the HSL color space is not perceptually uniform, one can see streaks of perceived brightness at yellow, cyan, and magenta (even though their absolute values are the same as red, green, and blue) and a halo around L = 1 / 2 . Use of the Lab color space corrects this, making the images more accurate, but also makes them more drab/pastel.

    Default is "cam16"; very similar is "cielab" (not shown here).

Consider the test function (z ** 2 - 1) * (z - 2 - 1j) ** 2 / (z ** 2 + 2 + 2j):

alpha = 1 alpha = 0.5 alpha = 0.0

The representation is chosen such that

  • values around 0 are black,
  • values around infinity are white,
  • values around +1 are green,
  • values around -1 are deep purple,
  • values around +i are blue,
  • values around -i are orange.

(Compare to the z1 reference plot below.)

With this, it is easy to see where a function has very small and very large values, and the multiplicty of zeros and poles is instantly identified by counting the color wheel passes around a black or white point.

Gallery

All plots are created with default settings.

| | :-------------------:|:------------------:|:----------:| z**1 | z**2 | z**3 |

| | | :-------------------:|:------------------:|:----------:| 1/z | z / abs(z) | (z+1) / (z-1) |

| | :-------------------:|:------------------:|:-------------------------:| numpy.sqrt | x**(1/3) | x**(1/4) |

| :-------------------:|:------------------:|:-------------------------:| numpy.log | numpy.exp | exp(1/x) |

| | :-------------------:|:------------------:|:-------------------------:| numpy.sin | numpy.cos | numpy.tan |

| | :-------------------:|:------------------:|:-------------------------:| numpy.sinh | numpy.cosh | numpy.tanh |

| | :-------------------:|:------------------:|:-------------------------:| numpy.arcsin | numpy.arccos | numpy.arctan |

| | :-------------------:|:------------------:|:-------------------------:| scipy.special.gamma | scipy.special.digamma | mpmath.zeta |

Testing

To run the cplot unit tests, check out this repository and type

pytest

License

cplot is published under the MIT license.

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

cplot-0.2.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

cplot-0.2.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cplot-0.2.0.tar.gz
  • Upload date:
  • Size: 9.7 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.32.2 CPython/3.7.4rc2

File hashes

Hashes for cplot-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8aee2c45b9b9d0e72304d0859bd0097d43768e345c8bb41cf7048889e04d0198
MD5 6b2e4fdca6f4a2c1d284bb6a843f1ba8
BLAKE2b-256 7d4bea68e1a4f2dd3b867067f7b3fdb4bdbf971f04daec065ce7569b9eb08165

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cplot-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 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.32.2 CPython/3.7.4rc2

File hashes

Hashes for cplot-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0177aa183c671af33c473b2931ded1cdeea17578c4953304b60ec654e10274b
MD5 87ddc22e7de9c0ebf96f26908ad5f369
BLAKE2b-256 2452d33f838c92816ff55f8168a4a807c86c52c4fb5d7e202b3374e10a63b105

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