Skip to main content

Plotting tools for complex-valued functions

Project description

cplot

Plot complex-valued functions with style.

PyPi Version PyPI pyversions GitHub stars PyPi downloads

Discord

gh-actions codecov Code style: black

cplot helps plotting complex-valued functions in a visually appealing manner.

There are two basic building blocks:

  • Contours along constant absolute value and/or the constant argument (phase, angle)
  • domain coloring, i.e., mapping the absolute value to lightness and the complex argument to the chroma of the representing color

Install with

pip install cplot

and use as

import cplot
import numpy as np

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

cplot.savefig("out.png", np.tan, (-5, +5), (-5, +5), 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)

cplot.show takes further additional arguments, e.g.,

abs_scaling = "h-1.0"  # how to scale the lightness in domain coloring
colorspace = "cam16"  # ditto
levels = (7, 4)  # number of abs/arg contours
colors = "#a0a0a050"  # contour color
linestyles = "solid"  # contour line style
  • By default, the abs contour levels are [1/8, 1/4, 1/2, 1, 2, 4, 8]; the arg contours levels are [0, pi/2, pi, -pi/2]. It is possible to pass level lists explicitly. Pass 0 or None to disable the levels completely.

  • abs_scaling can be used to adjust the use of colors. h with a value less than 1.0 adds more color which can help isolating the roots and poles (which are still black and white, respectively). h-0.0 ignores the magnitude of f(z) completely. arctan is another possible scaling.

  • 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 (math rendered with xdoc)

f(z) = \frac{(z^2 - 1) (z - 2 - 1j)^2}{z^2 + 2 + 2j}
h-1.0 h-0.5 h-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)
z ** z (1/z) ** z z ** (1/z)
np.sqrt z**(1/3) z**(1/4)
np.log np.exp exp(1/z)
np.sin np.cos np.tan
np.sinh np.cosh np.tanh
np.arcsin np.arccos np.arctan
sin(z) / z cos(z) / z tan(z) / z
scipy.special.gamma scipy.special.digamma mpmath.zeta
mpmath.siegeltheta mpmath.siegelz Riemann-Xi

Testing

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

pytest

Similar projects and further reading

License

This software is published under the GPLv3 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.4.0.tar.gz (26.0 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.4.0-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cplot-0.4.0.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for cplot-0.4.0.tar.gz
Algorithm Hash digest
SHA256 3fcb02f9daf0584545e0b96847c3fe89bc02159f33703f7c6de1336971df1e41
MD5 27bac42bf3a55c81afaf7b5ab42bb4aa
BLAKE2b-256 66f7e0a45e955ac1781ec533a4db00f54b650ac6ceaeebf12152db1c79bf226a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cplot-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for cplot-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f7c5989b85400c60725a9178c5e00a1810176418b1ec8cea505731ad23d56d50
MD5 7e31b5aeb986cfe1a844e713058c7950
BLAKE2b-256 5137d24acb76965eff394ecb0015a546283b46222fea6d5d4a544121bec29a57

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