Skip to main content

Plot complex-valued functions

Project description


Plot complex-valued functions with style.

PyPi Version PyPI pyversions GitHub stars PyPi downloads


gh-actions codecov Code style: black

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

Install with

pip install cplot

and use as

import numpy as np

import cplot

def f(z):
    return np.sin(z ** 3) / z

plt = cplot.plot(
    (-2.0, +2.0),
    (-2.0, +2.0),
    # colorbars: bool = True,
    # abs_scaling="h-1.0",        # how to scale the lightness in domain coloring
    # colorspace: str = "cam16",  # ditto
    # abs/args contour lines:
    # contours=("auto", (-np.pi / 2, 0, np.pi / 2, np.pi)),
    # linecolors = "#a0a0a050",
    # linestyles = "solid",
    # linestyle_abs1 = "solid"

The plot consists of three building blocks:

  • domain coloring, i.e., mapping the absolute value to lightness and the complex argument to the chroma of the representing color
  • Contours of constant absolute value (the contour abs(z) == 1 is dashed, the other contours are at (2, 4, 8, etc. and 1/2, 1/4, 1/8, etc., respectively)
  • Contours along constant argument (angle). For arg(z) == 0, the color is green, for arg(z) == pi/2 it's orange, for arg(z) = -pi / 2 it's blue, and for arg(z) = pi it's pink

Other useful functions:

# 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 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


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


Similar projects and further reading

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for cplot, version 0.5.1
Filename, size File type Python version Upload date Hashes
Filename, size cplot-0.5.1-py3-none-any.whl (26.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size cplot-0.5.1.tar.gz (26.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page