I am currently learning SciPy
and I want to play a little bit with pylab
and matplotlib
so as an exercise I tried to visualize Reddit
's hot
function.
Of course this code is not working, and I can't really figure out how to google what I want.
from pylab import *
import numpy as np
def f(t,v):
y = lambda a : 1 if a > 0 else (-1 if a < 0 else 0)
z = lambda a : log10(abs(a)) if abs(a) >= 1 else log10(1)
return map(z,v)*map(y,v) + t
n = 256
x = np.linspace(0,100,n)
y = np.linspace(-50,+50,n)
X,Y = np.meshgrid(x,y)
contourf(X, Y, f(X,Y), 15, alpha=.75, cmap='jet')
C = contour(X, Y, f(X,Y), 15, colors='black', linewidth=.5)
show()
EDIT: By not working it means that it is giving me the following error message:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-33-a1d2f439ebda> in <module>()
13 X,Y = np.meshgrid(x,y)
14
---> 15 contourf(X, Y, f(X,Y), 15, alpha=.75, cmap='jet')
16 C = contour(X, Y, f(X,Y), 15, colors='black', linewidth=.5)
17 show()
<ipython-input-33-a1d2f439ebda> in f(t, v)
6 z = lambda a : log10(abs(a)) if abs(a) >= 1 else log10(1)
7
----> 8 return map(z,v)*map(y,v) + t
9
10 n = 256
<ipython-input-33-a1d2f439ebda> in <lambda>(a)
4 y = lambda a : 1 if a > 0 else (-1 if a < 0 else 0)
5
----> 6 z = lambda a : log10(abs(a)) if abs(a) >= 1 else log10(1)
7
8 return map(z,v)*map(y,v) + t
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()