• Stars
    star
    149
  • Rank 248,619 (Top 5 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created almost 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐ŸŒˆ Plot complex functions

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,
    # linewidth = 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

All plots are created with default settings.

z ** 1 z ** 2 z ** 3
Many more plots
1 / z 1 / z ** 2 1 / z ** 3
(z + 1) / (z - 1) Another Mรถbius transformation A third Mรถbius transformation
np.real z / abs(z) np.conj
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.log np.exp np.exp2
np.exp(1 / z) z * np.sin(1 / z) np.cos(1 / z)
exp(- z ** 2) 1 / (1 + z ** 2) Error function
np.sin np.cos np.tan
sec csc cot
np.sinh np.cosh np.tanh
secans hyperbolicus cosecans hyperbolicus cotangent hyperbolicus
np.arcsin np.arccos np.arctan
np.arcsinh np.arccosh np.arctanh
Sinc, sin(z) / z cos(z) / z tan(z) / z
Integral sine Si Integral cosine Ci Lambert W function
Gudermannian function Exponential integral E1 Exponential integral Ei
mpmath.zeta Bernoulli function Dirichlet eta function
Hurwitz zeta function with a = 1/3 Hurwitz zeta function with a = 24/25 Hurwitz zeta function with s = 3 + 4i
scipy.special.gamma reciprocal Gamma scipy.special.loggamma
scipy.special.digamma Polygamma 1 Polygamma 2
Riemann-Siegel theta function Z-function Riemann-Xi
Jacobi elliptic function sn(0.6) cn(0.6) dn(0.6)
Jacobi theta 1 with q=0.1 * exp(0.1j * np.pi)) Jacobi theta 2 with the same q Jacobi theta 3 with the same q
Bessel function, first kind, order 1 Bessel function, first kind, order 2 Bessel function, first kind, order 3
Bessel function, second kind, order 1 Bessel function, second kind, order 2 Bessel function, second kind, order 3
Hankel function of first kind (n=1.0) Hankel function of first kind (n=3.1) Hankel function of second kind (n=1.0)
Fresnel S Fresnel C Faddeeva function
Airy function Ai Bi Exponentially scaled eAi
tanh(pi / 2 * sinh(z)) sinh(pi / 2 * sinh(z)) exp(pi / 2 * sinh(z))
Klein's j-invariant Dedekind eta function
Lambert series with 1s Lambert series with von-Mangoldt-coefficients Lambert series with Liouville-coefficients

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.

More Repositories

1

tikzplotlib

๐Ÿ“Š Save matplotlib figures as TikZ/PGFplots for smooth integration into LaTeX.
Python
2,398
star
2

meshio

๐Ÿ•ธ๏ธ input/output for many mesh formats
Python
1,930
star
3

tiptop

๐Ÿ–ฅ๏ธ Command-line system monitoring
Python
1,749
star
4

tuna

๐ŸŸ Python profile viewer
Python
1,363
star
5

perfplot

๐Ÿ“ˆ Performance analysis for Python snippets
Python
1,339
star
6

awesome-scientific-computing

๐Ÿ˜Ž Curated list of awesome software for numerical analysis and scientific computing
Python
1,319
star
7

pygmsh

๐Ÿ•ธ๏ธ Gmsh for Python
Python
844
star
8

matplotx

๐Ÿ“Š More styles and useful extensions for Matplotlib
Python
789
star
9

termplotlib

๐Ÿ“ˆ Plotting on the command line
Python
669
star
10

colorio

๐ŸŒˆ Tools for color research
TeX
320
star
11

stressberry

Stress tests for the Raspberry Pi ๐Ÿ˜…
Python
319
star
12

github-trends

๐Ÿ“ˆ GitHub star history plots
260
star
13

dufte

๐Ÿ“ˆ Minimalistic Matplotlib style
Python
216
star
14

deadlink

๐Ÿ’€ Checks and fixes URLs in code and documentation.
Python
162
star
15

termtables

๐Ÿ–ฅ๏ธ Pretty tables in the terminal
Python
98
star
16

pytest-codeblocks

๐Ÿ“„ Test code blocks in your READMEs
Python
95
star
17

action-cached-lfs-checkout

GitHub checkout action with LFS files pulled from cache
Just
90
star
18

ua-beamer

A LaTeX beamer theme for the University of Antwerp
TeX
75
star
19

pipdate

Small pip update helpers.
Python
73
star
20

matlab-guidelines

Guidelines for writing clean and fast code in MATLAB
TeX
67
star
21

spectro

๐ŸŽต Audio file analysis
Python
47
star
22

tablign

Aligns columns in your ASCII tables on the command line or in vim.
Python
43
star
23

pyfoobar

Python project template/scaffold and best practices
Python
41
star
24

betterspy

๐Ÿ‘€ Visualization for SciPy sparse matrices.
Python
40
star
25

color-data

๐ŸŒˆ Collected experimental data for color research
Python
39
star
26

stackoverflow-trends

๐Ÿ“ˆ StackOverflow trends
35
star
27

xhub

๐Ÿ“ GitHub with LaTeX math, diagrams, etc.
JavaScript
35
star
28

maelstrom

Numerical simulation of magnetohydrodynamics.
Python
33
star
29

purple-pi

๐Ÿ’œ LaTeX math wherever you want
JavaScript
31
star
30

stackoverflow-card

JavaScript
31
star
31

markdown-math-acid-test

Showcase GitHub math bugs
25
star
32

fontman

Manage and update your installed fonts.
Python
21
star
33

tau

The better pi
Python
20
star
34

pyfma

Fused multiply-add (with a single rounding) for Python.
Python
20
star
35

scipyx

SciPy fixes and extensions
Python
18
star
36

gitfaces

Fetch contributor avatars for a GitHub repository
Python
17
star
37

epicycler

Create epicycle animations.
Python
15
star
38

fjson

Python JSON writer with formatted floats
Python
14
star
39

python-vs-cpp

C++
13
star
40

identinum

Identify exact expression for decimal.
Python
9
star
41

mikado

Friendly solver interfaces for Trilinos.
C++
8
star
42

materials

Density, magnetic permeability etc. for a range of materials.
Python
8
star
43

note-on-cam16

Algorithmic improvements for the CIECAM02 and CAM16 color appearence models
TeX
8
star
44

matheon-html5-template

Matheon HTML5 presentation template
JavaScript
8
star
45

flow

Navier-Stokes and heat equation with FEniCS.
Python
5
star
46

nosh

A numerical solver for nonlinear Schrรถdinger equations
C++
4
star
47

tex-font-errors-cheatsheet

Cheat sheet(s) for decoding the meaning of TeX font errors
3
star
48

rhino

Python
3
star
49

vandermonde

๐Ÿ“ Tools for working with Vandermonde matrices, e.g., Bjรถrck-Pereyra.
Python
3
star
50

keygen_licensing_tools

Tools for license valididation with Keygen.sh
Python
3
star
51

corona-charts

Corona data and charts, updated automatically
Python
2
star
52

plm

Python
2
star
53

math-test

2
star
54

github-mathml-test

2
star
55

parabolic

Time stepping methods for parabolic problems.
Python
2
star
56

sippp

Fortran library for the solution of singularly perturbed parabolic problems
Fortran
2
star
57

nschloe.github.io

HTML
2
star
58

hanoi-material

Class material for nonlinear optimization at Hanoi Autumn School 2013
MATLAB
2
star
59

talk-python-scientific

Python in Scientific Computation
JavaScript
2
star
60

trilinos-tutorial

C++
1
star
61

tspsolve

Solution algorithms for the travelling salesman problem.
Python
1
star
62

launchpadtools

Tools for submitting packages to Ubuntu Launchpad
Python
1
star
63

nschloe

about me
1
star