Project description
Plot complex-valued functions with style.
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="auto",
# contours_arg=(-np.pi / 2, 0, np.pi / 2, np.pi),
# highlight_abs_contour_1: bool = True,
# colorspace: str = "cam16",
# add_colorbars: bool = True,
# add_axes_labels: bool = True,
# saturation_adjustment: float = 1.28,
)
plt.show()
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 highlighted, 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 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)
Gallery
All plots are created with default settings.
|
|
|
1 / z |
1 / z ** 2 |
(z + 1) / (z - 1) |
|
|
|
z ** 6 + 1 |
z ** 6 - 1 |
z ** (-6) + 1 |
|
|
|
z ** z |
(1/z) ** z |
z ** (1/z) |
|
|
|
np.sqrt |
z**(1/3) |
z**(1/4) |
|
|
|
np.real |
z / abs(z) |
np.conj |
|
|
|
np.exp(1 / z) |
z * np.sin(1 / z) |
np.cos(1 / z) |
|
|
|
exp(- z ** 2) |
1 / (1 + z ** 2) |
scipy.special.erf |
|
|
|
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 |
|
|
|
Jacobi elliptic function sn(0.6) |
cn(0.6) |
dn(0.6) |
|
|
|
Bessel function, first kind, order 1 |
order 2 |
order 3 |
|
|
|
Airy function Ai |
Bi |
Exponentially scaled eAi |
|
|
|
tanh(pi / 2 * sinh(z)) |
sinh(pi / 2 * sinh(z)) |
exp(pi / 2 * sinh(z)) |
Testing
To run the cplot unit tests, check out this repository and run
tox
Similar projects and further reading
- Tristan Needham, Visual Complex
Analysis, 1997
- François Labelle, A Gallery of Complex
Functions, 2002
- Douglas Arnold and Jonathan Rogness, Möbius transformations
revealed, 2008
- Konstantin Poelke and Konrad Polthier, Lifted Domain Coloring,
2009
- Elias Wegert and Gunter Semmler, Phase Plots of Complex Functions:
a Journey in Illustration, 2011
- Elias Wegert,
Calendars "Complex Beauties, 2011-
- Elias Wegert, Visual Complex
Functions, 2012
- John D. Cook, Visualizing complex
functions, 2017
- endolith, complex-colormap, 2017
- Anthony Hernandez, dcolor, 2017
- Juan Carlos Ponce Campuzano, DC
gallery, 2018
- 3Blue1Brown, Winding numbers and domain coloring, 2018
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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution