Skip to main content

Plot complex-valued functions

Project description

cplot

Plot complex-valued functions with style.

PyPi Version PyPI pyversions DOI GitHub stars Downloads

Discord

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(
    f,
    (-2.0, +2.0, 400),
    (-2.0, +2.0, 400),
    # abs_scaling=lambda x: x / (x + 1),  # how to scale the lightness in domain coloring
    # contours_abs=2.0,
    # contours_arg=(-np.pi / 2, 0, np.pi / 2, np.pi),
    # emphasize_abs_contour_1: bool = True,
    # add_colorbars: bool = True,
    # add_axes_labels: bool = True,
    # saturation_adjustment: float = 1.28,
    # min_contour_length = None,
)
plt.show()

Historically, plotting of complex functions was in one of three ways

Only show the absolute value; sometimes as a 3D plot Only show the phase/the argument in a color wheel (phase portrait) Show contour lines for both arg and abs

Combining all three of them gives you a cplot:

See also Wikipedia: Domain coloring.

Features of this software:

  • cplot uses OKLAB, a perceptually uniform color space for the argument colors. This avoids streaks of colors occurring with other color spaces, e.g., HSL.
  • The contour abs(z) == 1 is emphasized, other abs contours are at 2, 4, 8, etc. and 1/2, 1/4, 1/8, etc., respectively. This makes it easy to tell the absolte value precisely.
  • For arg(z) == 0, the color is green, for arg(z) == pi/2 it's blue, for arg(z) = -pi / 2 it's orange, 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)

Riemann sphere

cplot can also plot functions on the Riemann sphere, a mapping of the complex plane to the unit ball.

import cplot
import numpy as np

cplot.riemann_sphere(np.log)

Gallery

This way to the gallery!

cplot

Testing

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

tox

Similar projects and further reading

License

This software is published under the GPL-3.0 license. In cases where the constraints of the GPL prevent you from using this software, feel free contact the author.

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.9.2.tar.gz (52.3 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.9.2-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cplot-0.9.2.tar.gz
  • Upload date:
  • Size: 52.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for cplot-0.9.2.tar.gz
Algorithm Hash digest
SHA256 62600b2b48f90dd4ed33bd775bd38aa24c06d269b4e4618f70188ec53950544d
MD5 f1662dcfbae26c1097c821c38f39682e
BLAKE2b-256 33c58258009c18f28e2db9f21d6cf1e28c92e554dd64f597a5996d327c94e1d1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cplot-0.9.2-py3-none-any.whl
  • Upload date:
  • Size: 39.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for cplot-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f90058310859f5977b1ca0945fed5787fb22e5a48c8cd73843b4e4fe8cfe9c94
MD5 003a20e4d4f4ee0dc7ebb1743812faff
BLAKE2b-256 84124ecff93f742ee20b68b23d18a30e29b8e98356853e255c940c1c5845c2f2

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