"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "mpmath/visualization.py" between
mpmath-0.19.tar.gz and mpmath-1.0.0.tar.gz

About: mpmath is a Python library for arbitrary-precision floating-point arithmetic.

visualization.py  (mpmath-0.19):visualization.py  (mpmath-1.0.0)
skipping to change at line 122 skipping to change at line 122
if ctx.isinf(z): if ctx.isinf(z):
return (1.0, 1.0, 1.0) return (1.0, 1.0, 1.0)
if ctx.isnan(z): if ctx.isnan(z):
return (0.5, 0.5, 0.5) return (0.5, 0.5, 0.5)
pi = 3.1415926535898 pi = 3.1415926535898
a = (float(ctx.arg(z)) + ctx.pi) / (2*ctx.pi) a = (float(ctx.arg(z)) + ctx.pi) / (2*ctx.pi)
a = (a + 0.5) % 1.0 a = (a + 0.5) % 1.0
b = 1.0 - float(1/(1.0+abs(z)**0.3)) b = 1.0 - float(1/(1.0+abs(z)**0.3))
return hls_to_rgb(a, b, 0.8) return hls_to_rgb(a, b, 0.8)
blue_orange_colors = [
(-1.0, (0.0, 0.0, 0.0)),
(-0.95, (0.1, 0.2, 0.5)), # dark blue
(-0.5, (0.0, 0.5, 1.0)), # blueish
(-0.05, (0.4, 0.8, 0.8)), # cyanish
( 0.0, (1.0, 1.0, 1.0)),
( 0.05, (1.0, 0.9, 0.3)), # yellowish
( 0.5, (0.9, 0.5, 0.0)), # orangeish
( 0.95, (0.7, 0.1, 0.0)), # redish
( 1.0, (0.0, 0.0, 0.0)),
( 2.0, (0.0, 0.0, 0.0)),
]
def phase_color_function(ctx, z):
if ctx.isinf(z):
return (1.0, 1.0, 1.0)
if ctx.isnan(z):
return (0.5, 0.5, 0.5)
pi = 3.1415926535898
w = float(ctx.arg(z)) / pi
w = max(min(w, 1.0), -1.0)
for i in range(1,len(blue_orange_colors)):
if blue_orange_colors[i][0] > w:
a, (ra, ga, ba) = blue_orange_colors[i-1]
b, (rb, gb, bb) = blue_orange_colors[i]
s = (w-a) / (b-a)
return ra+(rb-ra)*s, ga+(gb-ga)*s, ba+(bb-ba)*s
def cplot(ctx, f, re=[-5,5], im=[-5,5], points=2000, color=None, def cplot(ctx, f, re=[-5,5], im=[-5,5], points=2000, color=None,
verbose=False, file=None, dpi=None, axes=None): verbose=False, file=None, dpi=None, axes=None):
""" """
Plots the given complex-valued function *f* over a rectangular part Plots the given complex-valued function *f* over a rectangular part
of the complex plane specified by the pairs of intervals *re* and *im*. of the complex plane specified by the pairs of intervals *re* and *im*.
For example:: For example::
cplot(lambda z: z, [-2, 2], [-10, 10]) cplot(lambda z: z, [-2, 2], [-10, 10])
cplot(exp) cplot(exp)
cplot(zeta, [0, 1], [0, 50]) cplot(zeta, [0, 1], [0, 50])
By default, the complex argument (phase) is shown as color (hue) and By default, the complex argument (phase) is shown as color (hue) and
the magnitude is show as brightness. You can also supply a the magnitude is show as brightness. You can also supply a
custom color function (*color*). This function should take a custom color function (*color*). This function should take a
complex number as input and return an RGB 3-tuple containing complex number as input and return an RGB 3-tuple containing
floats in the range 0.0-1.0. floats in the range 0.0-1.0.
Alternatively, you can select a builtin color function by passing
a string as *color*:
* "default" - default color scheme
* "phase" - a color scheme that only renders the phase of the function,
with white for positive reals, black for negative reals, gold in the
upper half plane, and blue in the lower half plane.
To obtain a sharp image, the number of points may need to be To obtain a sharp image, the number of points may need to be
increased to 100,000 or thereabout. Since evaluating the increased to 100,000 or thereabout. Since evaluating the
function that many times is likely to be slow, the 'verbose' function that many times is likely to be slow, the 'verbose'
option is useful to display progress. option is useful to display progress.
.. note :: This function requires matplotlib (pylab). .. note :: This function requires matplotlib (pylab).
""" """
if color is None: if color is None or color == "default":
color = ctx.default_color_function color = ctx.default_color_function
if color == "phase":
color = ctx.phase_color_function
import pylab import pylab
if file: if file:
axes = None axes = None
fig = None fig = None
if not axes: if not axes:
fig = pylab.figure() fig = pylab.figure()
axes = fig.add_subplot(111) axes = fig.add_subplot(111)
rea, reb = re rea, reb = re
ima, imb = im ima, imb = im
dre = reb - rea dre = reb - rea
skipping to change at line 272 skipping to change at line 310
delta = maxd - dz delta = maxd - dz
axes.set_zlim3d(zab[0] - delta / 2.0, zab[1] + delta / 2.0) axes.set_zlim3d(zab[0] - delta / 2.0, zab[1] + delta / 2.0)
if fig: if fig:
if file: if file:
pylab.savefig(file, dpi=dpi) pylab.savefig(file, dpi=dpi)
else: else:
pylab.show() pylab.show()
VisualizationMethods.plot = plot VisualizationMethods.plot = plot
VisualizationMethods.default_color_function = default_color_function VisualizationMethods.default_color_function = default_color_function
VisualizationMethods.phase_color_function = phase_color_function
VisualizationMethods.cplot = cplot VisualizationMethods.cplot = cplot
VisualizationMethods.splot = splot VisualizationMethods.splot = splot
 End of changes. 5 change blocks. 
1 lines changed or deleted 40 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)