Project description
Plot complex-valued functions with style.
![PyPi downloads](https://pypi-camo.freetls.fastly.net/f8e7dbf3055e2841f888d971fc886bb24ef6da38/68747470733a2f2f696d672e736869656c64732e696f2f707970692f646d2f63706c6f742e7376673f7374796c653d666c61742d737175617265)
![Discord](https://pypi-camo.freetls.fastly.net/055c518ca68892192d788859638eda20f533413e/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6f676f3d646973636f7264266c6162656c3d63686174266d6573736167653d6f6e253230646973636f726426636f6c6f723d373238396461267374796c653d666c61742d737175617265)
![Code style: black](https://pypi-camo.freetls.fastly.net/1c326c58e924b9f3508f32a8ac6b3ee91f40b090/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307374796c652d626c61636b2d3030303030302e7376673f7374796c653d666c61742d737175617265)
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 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)
Gallery
All plots are created with default settings.
![](https://pypi-camo.freetls.fastly.net/dc376e6a63727a6605d916f01eeda0fab208be50/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f317a2e737667) |
![](https://pypi-camo.freetls.fastly.net/93a4bee11ab3eb42f86c8702637a3a51a1397660/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f7a2d6162737a2e737667) |
![](https://pypi-camo.freetls.fastly.net/8c2df34b71a7fd7658ee3a0d6addcd08c43f1105/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f7a2b312d7a2d312e737667) |
1/z |
z / abs(z) |
(z+1) / (z-1) |
![](https://pypi-camo.freetls.fastly.net/54b4d48fe8e3474de3e32d108354985cbbf67082/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f7a362b312e737667) |
![](https://pypi-camo.freetls.fastly.net/35cd9ca760941685451cb6485e57c4cc1c17364c/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f7a362d312e737667) |
![](https://pypi-camo.freetls.fastly.net/cb6c63974b754fd2c071f0540514b243074e6547/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f7a2d362b312e737667) |
z ** 6 + 1 |
z ** 6 - 1 |
z ** (-6) + 1 |
![](https://pypi-camo.freetls.fastly.net/05b852416214c8093221f202d1fc0a3b6bb2ee33/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f7a7a2e737667) |
![](https://pypi-camo.freetls.fastly.net/74691ad0bd0ce118c94e285f0fa9c5a1d478cd44/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f317a7a2e737667) |
![](https://pypi-camo.freetls.fastly.net/fedc7b24b60394e0bdf6503d6c078c039c684abd/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f7a317a2e737667) |
z ** z |
(1/z) ** z |
z ** (1/z) |
![](https://pypi-camo.freetls.fastly.net/1533b87347f2e2b167b1d2cfc61807cbb2a479e8/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f726f6f74322e737667) |
![](https://pypi-camo.freetls.fastly.net/0184cf61f981c166cd2218b830f3165fd185d496/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f726f6f74332e737667) |
![](https://pypi-camo.freetls.fastly.net/6541a8f2acac18ee6013dac62ecbe95a84ccf5c9/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f726f6f74342e737667) |
np.sqrt |
z**(1/3) |
z**(1/4) |
![](https://pypi-camo.freetls.fastly.net/115d59c6e65c3d3e4c0d2568dea1ce5c5037464c/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f657870317a2e737667) |
![](https://pypi-camo.freetls.fastly.net/fdd90e9d907ffb6c3abf06846d79e51881adf8c9/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f7a73696e317a2e737667) |
![](https://pypi-camo.freetls.fastly.net/5f8d078d4beaf53f1839a4b9b54f2213b1f256ce/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f636f73317a2e737667) |
np.exp(1 / z) |
z * np.sin(1 / z) |
np.cos(1 / z) |
![](https://pypi-camo.freetls.fastly.net/bfc616592e47d712208509967bc9eb911c82a78e/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f6578702d7a322e737667) |
![](https://pypi-camo.freetls.fastly.net/2a49cbaa4739f1c5196b351448194183191b4037/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f31317a322e737667) |
![](https://pypi-camo.freetls.fastly.net/3c70f711bbaefe9fe99f979faf754dd7ccc70a2c/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f6572662e737667) |
exp(- z ** 2) |
1 / (1 + z ** 2) |
scipy.special.erf |
![](https://pypi-camo.freetls.fastly.net/017fc4c0f1fa5b124cab83ae42e7e83cf1453c99/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f61726373696e2e737667) |
![](https://pypi-camo.freetls.fastly.net/7ed5763080fbd13d4c67391bf5c178ee4a53e9cd/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f617263636f732e737667) |
![](https://pypi-camo.freetls.fastly.net/b9006fad342f315eb032610b05b9194a1b6ca5bc/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f61726374616e2e737667) |
np.arcsin |
np.arccos |
np.arctan |
![](https://pypi-camo.freetls.fastly.net/f83e512c8d4de7826515a20945c8da115c1e792f/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f73696e7a2d7a2e737667) |
![](https://pypi-camo.freetls.fastly.net/c0d5923a5734e17a20b91b01f7047ee8dfc982e7/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f636f737a2d7a2e737667) |
![](https://pypi-camo.freetls.fastly.net/6e86d30eb16eb34234aa6413e4ac8ed25ac05684/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f74616e7a2d7a2e737667) |
sin(z) / z |
cos(z) / z |
tan(z) / z |
![](https://pypi-camo.freetls.fastly.net/1a4f820b72b6b2687e49bd5034418334d19a87f2/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f67616d6d612e737667) |
![](https://pypi-camo.freetls.fastly.net/e0e6702564a2a4625b60e056ed7f7403f6abb8ef/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f646967616d6d612e737667) |
![](https://pypi-camo.freetls.fastly.net/f900a2ba9e9a2c176055f230ce54319884dfee90/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f7a6574612e737667) |
scipy.special.gamma |
scipy.special.digamma |
mpmath.zeta |
![](https://pypi-camo.freetls.fastly.net/a47ae7de7c4b3176ebe09d5c0fa03617f224d796/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f7269656d616e6e2d73696567656c2d74686574612e737667) |
![](https://pypi-camo.freetls.fastly.net/99a71150044d6e2589dbe9fbac1d181444c81807/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f7269656d616e6e2d73696567656c2d7a2e737667) |
![](https://pypi-camo.freetls.fastly.net/91cd28338c20d72123e586030a8cf3fa8eae7643/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f7269656d616e6e2d78692e737667) |
mpmath.siegeltheta |
mpmath.siegelz |
Riemann-Xi |
![](https://pypi-camo.freetls.fastly.net/a2561f85a0d6ada4139bd3e8b0baaae2ae8545d0/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f656c6c69706a2d736e2d30362e737667) |
![](https://pypi-camo.freetls.fastly.net/574496e6bb91ec50f8cdf6051908f9e706a21557/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f656c6c69706a2d636e2d30362e737667) |
![](https://pypi-camo.freetls.fastly.net/ae28f2d9220ed99e03e76358077b7df1c332050d/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f656c6c69706a2d646e2d30362e737667) |
Jacobi elliptic function sn(0.6) |
cn(0.6) |
dn(0.6) |
![](https://pypi-camo.freetls.fastly.net/ae7043a031f8de7cd59f1690293c5ec4d55a9f58/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f62657373656c2d312e737667) |
![](https://pypi-camo.freetls.fastly.net/9505eb89bee37cd356e04c09e4585626cc7fd2df/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f62657373656c2d322e737667) |
![](https://pypi-camo.freetls.fastly.net/bc4b62b39d4e5400ebd8ca36f851ceb448b39097/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f62657373656c2d332e737667) |
Bessel function, first kind, order 1 |
order 2 |
order 3 |
![](https://pypi-camo.freetls.fastly.net/e504d10a9e4aca986858649a82642606e2172588/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f616972792d61692e737667) |
![](https://pypi-camo.freetls.fastly.net/f6316eb86b9a99e47954bd4da2dd56c9927d3737/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f616972792d62692e737667) |
![](https://pypi-camo.freetls.fastly.net/5d022396f95d5ddeef1474a52d965738a530b70d/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f61697279652d61692e737667) |
Airy function Ai |
Bi |
Exponentially scaled eAi |
![](https://pypi-camo.freetls.fastly.net/3fe363d478393c4fec8826ef2d137f6dbbc74db4/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f74616e682d73696e682e737667) |
![](https://pypi-camo.freetls.fastly.net/6be7c18d4be08e08923162e5165bb0dfb93d3ba5/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f73696e682d73696e682e737667) |
![](https://pypi-camo.freetls.fastly.net/5decf16e1628f0c029a0f28ab4c8d58731f7bf81/68747470733a2f2f6e7363686c6f652e6769746875622e696f2f63706c6f742f6578702d73696e682e737667) |
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
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