Coverage for local/lib/python2.7/site-packages/sage/plot/complex_plot.pyx : 94%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Complex Plots """
#***************************************************************************** # Copyright (C) 2009 Robert Bradshaw <robertwb@math.washington.edu>, # # Distributed under the terms of the GNU General Public License (GPL) # # This code is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # The full text of the GPL is available at: # # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import absolute_import
# TODO: use NumPy buffers and complex fast_callable (when supported) from cysignals.signals cimport sig_on, sig_off
cimport numpy as cnumpy
from sage.rings.complex_double cimport ComplexDoubleElement
from libc.math cimport hypot, atan2, atan, log, sqrt
cdef inline ComplexDoubleElement new_CDF_element(double x, double y):
cdef inline double mag_to_lightness(double r): """ Tweak this to adjust how the magnitude affects the color. For instance, changing ``sqrt(r)`` to ``r`` will cause anything near a zero to be much darker and poles to be much lighter, while ``r**(.25)`` would cause the reverse effect.
INPUT:
- ``r`` - a non-negative real number
OUTPUT:
A value between `-1` (black) and `+1` (white), inclusive.
EXAMPLES:
This tests it implicitly::
sage: from sage.plot.complex_plot import complex_to_rgb sage: complex_to_rgb([[0, 1, 10]]) array([[[ 0. , 0. , 0. ], [ 0.77172568, 0. , 0. ], [ 1. , 0.22134776, 0.22134776]]]) """
""" INPUT:
- ``z_values`` -- A grid of complex numbers, as a list of lists
OUTPUT:
An `N \\times M \\times 3` floating point Numpy array ``X``, where ``X[i,j]`` is an (r,g,b) tuple.
EXAMPLES::
sage: from sage.plot.complex_plot import complex_to_rgb sage: complex_to_rgb([[0, 1, 1000]]) array([[[ 0. , 0. , 0. ], [ 0.77172568, 0. , 0. ], [ 1. , 0.64421177, 0.64421177]]]) sage: complex_to_rgb([[0, 1j, 1000j]]) array([[[ 0. , 0. , 0. ], [ 0.38586284, 0.77172568, 0. ], [ 0.82210588, 1. , 0.64421177]]]) """ cdef unsigned int i, j, imax, jmax cdef double x, y, mag, arg cdef double lightness, hue, top, bot cdef double r, g, b cdef int ihue cdef ComplexDoubleElement z
else:
else: # in hsv, variable saturation, full value (v=1, s=1-lightness)
elif ihue == 1: elif ihue == 2: elif ihue == 3: elif ihue == 4: else:
""" The GraphicsPrimitive to display complex functions in using the domain coloring method
INPUT:
- ``rgb_data`` -- An array of colored points to be plotted.
- ``xrange`` -- A minimum and maximum x value for the plot.
- ``yrange`` -- A minimum and maximum y value for the plot.
TESTS::
sage: p = complex_plot(lambda z: z^2-1, (-2, 2), (-2, 2)) """ """ TESTS::
sage: p = complex_plot(lambda z: z^2-1, (-2, 2), (-2, 2)) """
""" Returns a dictionary with the bounding box data.
EXAMPLES::
sage: p = complex_plot(lambda z: z, (-1, 2), (-3, 4)) sage: sorted(p.get_minmax_data().items()) [('xmax', 2.0), ('xmin', -1.0), ('ymax', 4.0), ('ymin', -3.0)] """
""" TESTS::
sage: isinstance(complex_plot(lambda z: z, (-1,1), (-1,1))[0]._allowed_options(), dict) True """ 'interpolation':'What interpolation method to use'}
""" TESTS::
sage: isinstance(complex_plot(lambda z: z, (-1,1), (-1,1))[0]._repr_(), str) True """
""" TESTS::
sage: complex_plot(lambda x: x^2, (-5, 5), (-5, 5)) Graphics object consisting of 1 graphics primitive """
r""" ``complex_plot`` takes a complex function of one variable, `f(z)` and plots output of the function over the specified ``xrange`` and ``yrange`` as demonstrated below. The magnitude of the output is indicated by the brightness (with zero being black and infinity being white) while the argument is represented by the hue (with red being positive real, and increasing through orange, yellow, ... as the argument increases).
``complex_plot(f, (xmin, xmax), (ymin, ymax), ...)``
INPUT:
- ``f`` -- a function of a single complex value `x + iy`
- ``(xmin, xmax)`` -- 2-tuple, the range of ``x`` values
- ``(ymin, ymax)`` -- 2-tuple, the range of ``y`` values
The following inputs must all be passed in as named parameters:
- ``plot_points`` -- integer (default: 100); number of points to plot in each direction of the grid
- ``interpolation`` -- string (default: ``'catrom'``), the interpolation method to use: ``'bilinear'``, ``'bicubic'``, ``'spline16'``, ``'spline36'``, ``'quadric'``, ``'gaussian'``, ``'sinc'``, ``'bessel'``, ``'mitchell'``, ``'lanczos'``, ``'catrom'``, ``'hermite'``, ``'hanning'``, ``'hamming'``, ``'kaiser'``
EXAMPLES:
Here we plot a couple of simple functions::
sage: complex_plot(sqrt(x), (-5, 5), (-5, 5)) Graphics object consisting of 1 graphics primitive
.. PLOT::
sphinx_plot(complex_plot(sqrt(x), (-5, 5), (-5, 5)))
::
sage: complex_plot(sin(x), (-5, 5), (-5, 5)) Graphics object consisting of 1 graphics primitive
.. PLOT::
sphinx_plot(complex_plot(sin(x), (-5, 5), (-5, 5)))
::
sage: complex_plot(log(x), (-10, 10), (-10, 10)) Graphics object consisting of 1 graphics primitive
.. PLOT::
sphinx_plot(complex_plot(log(x), (-10, 10), (-10, 10)))
::
sage: complex_plot(exp(x), (-10, 10), (-10, 10)) Graphics object consisting of 1 graphics primitive
.. PLOT::
sphinx_plot(complex_plot(exp(x), (-10, 10), (-10, 10)))
A function with some nice zeros and a pole::
sage: f(z) = z^5 + z - 1 + 1/z sage: complex_plot(f, (-3, 3), (-3, 3)) Graphics object consisting of 1 graphics primitive
.. PLOT::
def f(z): return z**5 + z - 1 + 1/z sphinx_plot(complex_plot(f, (-3, 3), (-3, 3)))
Here is the identity, useful for seeing what values map to what colors::
sage: complex_plot(lambda z: z, (-3, 3), (-3, 3)) Graphics object consisting of 1 graphics primitive
.. PLOT::
sphinx_plot(complex_plot(lambda z: z, (-3, 3), (-3, 3)))
The Riemann Zeta function::
sage: complex_plot(zeta, (-30,30), (-30,30)) Graphics object consisting of 1 graphics primitive
.. PLOT::
sphinx_plot(complex_plot(zeta, (-30,30), (-30,30)))
Extra options will get passed on to show(), as long as they are valid::
sage: complex_plot(lambda z: z, (-3, 3), (-3, 3), figsize=[1,1]) Graphics object consisting of 1 graphics primitive
::
sage: complex_plot(lambda z: z, (-3, 3), (-3, 3)).show(figsize=[1,1]) # These are equivalent
TESTS:
Test to make sure that using fast_callable functions works::
sage: f(x) = x^2 sage: g = fast_callable(f, domain=CC, vars='x') sage: h = fast_callable(f, domain=CDF, vars='x') sage: P = complex_plot(f, (-10, 10), (-10, 10)) sage: Q = complex_plot(g, (-10, 10), (-10, 10)) sage: R = complex_plot(h, (-10, 10), (-10, 10)) sage: S = complex_plot(exp(x)-sin(x), (-10, 10), (-10, 10)) sage: P; Q; R; S Graphics object consisting of 1 graphics primitive Graphics object consisting of 1 graphics primitive Graphics object consisting of 1 graphics primitive Graphics object consisting of 1 graphics primitive
Test to make sure symbolic functions still work without declaring a variable. (We don't do this in practice because it doesn't use fast_callable, so it is much slower.)
::
sage: complex_plot(sqrt, (-5, 5), (-5, 5)) Graphics object consisting of 1 graphics primitive """
pass
cdef double x, y |