Wednesday, September 28, 2016

Roger Walsh: Closer to Truth: Why is Consciousness so Baffling?

Roger Walsh

  • polyphasic culture
  • experiential map
  • EEG

George Lakoff: Closer to Truth: Why is Consciousness so Baffling?

George Lakoff

Ken Mogi: Closer to Truth: What Is Consciousness?

Ken Mogi

Python: Matplotlib: Streamplot (2D Vector Field) Example

Noteworthy:

numpy.mgrid
numpy.sqrt
matplotlib.pyplot.subplots()
matplotlib.pyplot.cm.autumn
streamplot()
strm.linesspeed.max()


Command:

$ cat Downloads/streamplot_demo_features.py


Result:

"""
Demo of the `streamplot` function.

A streamplot, or streamline plot, is used to display 2D vector fields. This
example shows a few features of the stream plot function:

    * Varying the color along a streamline.
    * Varying the density of streamlines.
    * Varying the line width along a stream line.
"""
import numpy as np
import matplotlib.pyplot as plt

plt.style.use('dark_background')

Y, X = np.mgrid[-3:3:100j, -3:3:100j]
U = -1 - X**2 + Y
V = 1 + X - Y**2
speed = np.sqrt(U*U + V*V)

fig0, ax0 = plt.subplots()
strm = ax0.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=plt.cm.autumn)
fig0.colorbar(strm.lines)

fig1, (ax1, ax2) = plt.subplots(ncols=2)
ax1.streamplot(X, Y, U, V, density=[0.5, 1])

lw = 5*speed / speed.max()
ax2.streamplot(X, Y, U, V, density=0.6, color='k', linewidth=lw)

plt.show()


Command:

$ python Downloads/streamplot_demo_features.py


Graphical output:

fig0

fig1 (w/ unknown error on right side)
fig1 (Normal background style)


Python: Matplotlib: Sine Function Example

Noteworthy:

numpy.sin()
numpy.pi


Command:

$ cat Downloads/simple_plot.py


Result:

import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2*np.pi*t)
plt.plot(t, s)

plt.xlabel('time (s)')
plt.ylabel('voltage (mV)')
plt.title('About as simple as it gets, folks')
plt.grid(True)
plt.savefig("test.png")
plt.show()


Command:

$ python Downloads/simple_plot.py


Graphical output:

Python: Matplotlib: Lorenz Attractor Example

Noteworthy:

def
for in
range()
numpy.empty()
set_xlabel()
set_ylabel()
set_zlabel()
set_title()


Command:

$ cat Downloads/lorenz_attractor.py


Result:

# Plot of the Lorenz Attractor based on Edward Lorenz's 1963 "Deterministic
# Nonperiodic Flow" publication.
# http://journals.ametsoc.org/doi/abs/10.1175/1520-0469%281963%29020%3C0130%3ADNF%3E2.0.CO%3B2
#
# Note: Because this is a simple non-linear ODE, it would be more easily
#       done using SciPy's ode solver, but this approach depends only
#       upon NumPy.

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

plt.style.use('dark_background')

def lorenz(x, y, z, s=10, r=28, b=2.667):
    x_dot = s*(y - x)
    y_dot = r*x - y - x*z
    z_dot = x*y - b*z
    return x_dot, y_dot, z_dot


dt = 0.01
stepCnt = 10000

# Need one more for the initial values
xs = np.empty((stepCnt + 1,))
ys = np.empty((stepCnt + 1,))
zs = np.empty((stepCnt + 1,))

# Setting initial values
xs[0], ys[0], zs[0] = (0., 1., 1.05)

# Stepping through "time".
for i in range(stepCnt):
    # Derivatives of the X, Y, Z state
    x_dot, y_dot, z_dot = lorenz(xs[i], ys[i], zs[i])
    xs[i + 1] = xs[i] + (x_dot * dt)
    ys[i + 1] = ys[i] + (y_dot * dt)
    zs[i + 1] = zs[i] + (z_dot * dt)

fig = plt.figure()
ax = fig.gca(projection='3d')

ax.plot(xs, ys, zs)
ax.set_xlabel("X Axis")
ax.set_ylabel("Y Axis")
ax.set_zlabel("Z Axis")
ax.set_title("Lorenz Attractor")

plt.show()


Command:

$ python Downloads/lorenz_attractor.py


Graphical output:

Python: Matplotlib: Tri-Surface plots Example

Noteworthy:

# "Repeat elements of an array."
numpy.repeat(a, repeats, axis=None)

# "Append values to the end of an array."
numpy.append(arr, values, axis=None)

# "Create a tri-surface plot."
Axes3D.plot_trisurf(*args, **kwargs)


Command:

$ cat Downloads/trisurf3d_demo.py


Result:

from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('dark_background')
n_angles = 36
n_radii = 8

# An array of radii
# Does not include radius r=0, this is to eliminate duplicate points
radii = np.linspace(0.125, 1.0, n_radii)

# An array of angles
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)

# Repeat all angles for each radius
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)

# Convert polar (radii, angles) coords to cartesian (x, y) coords
# (0, 0) is added here. There are no duplicate points in the (x, y) plane
x = np.append(0, (radii*np.cos(angles)).flatten())
y = np.append(0, (radii*np.sin(angles)).flatten())

# Pringle surface
z = np.sin(-x*y)

fig = plt.figure()
ax = fig.gca(projection='3d')

ax.plot_trisurf(x, y, z, cmap=cm.jet, linewidth=0.2)

plt.show()


Command:

$ python Downloads/trisurf3d_demo.py


Graphical output:



Tuesday, September 27, 2016

Python: Matplotlib: 3D Plot Example

Noteworthy:

# "Creates a new figure."
matplotlib.pyplot.figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True, FigureClass=<class 'matplotlib.figure.Figure'>, **kwargs)

# "Renders into a FigureCanvas."
class matplotlib.figure.Figure(figsize=None, dpi=None, facecolor=None, edgecolor=None, linewidth=0.0, frameon=None, subplotpars=None, tight_layout=None)

# "Get the current Axes instance on the current figure matching the given keyword args, or create one."
matplotlib.pyplot.gca(**kwargs)

# "Return evenly spaced values within a given interval."
numpy.arange([start, ]stop, [step, ]dtype=None)

# "Return coordinate matrices from coordinate vectors."
numpy.meshgrid(*xi, **kwargs)

# "Return the positive square-root of an array, element-wise."
numpy.sqrt(x[, out]) = <ufunc 'sqrt'>

# "Trigonometric sine, element-wise."
numpy.sin(x[, out]) = <ufunc 'sin'>

# "Create a surface plot."
Axes3D.plot_surface(X, Y, Z, *args, **kwargs)


Command:

$ cat test3dplot.py


Result:

#!/usr/local/bin/python

from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('dark_background')
fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm)
plt.show()


Command:

$ python test3dplot.py

Graphical output:

Python: Matplotlib: Histogram Dark Background Example

Command:

$ cat testhistogram.py


Result:

#!/usr/local/bin/python

import matplotlib.pyplot as plt
plt.style.use('dark_background')

from numpy.random import normal,rand
x = normal(size=200)
plt.hist(x,bins=30)
plt.show()


Command:

$ python testhistogram.py


Graphical output:

Python: Matplotlib: Scatter Plot Dark Background Example

Command:

$ cat testscatterplot.py


Result:

#!/usr/local/bin/python

import matplotlib.pyplot as plt
plt.style.use('dark_background')

from numpy.random import rand
a = rand(100)
b = rand(100)
plt.scatter(a,b)
plt.show()


Command:

$ python testscatterplot.py


Graphical output:



Python: Matplotlib: Dark Background Example

Noteworthy:

# "Use matplotlib style settings from a style specification."
matplotlib.style.use(style)

# "Return the length (the number of items) of an object."
len(s)

# "An instance of RcParams for handling default matplotlib values."
matplotlib.rcParams

# "Set the x axis label of the current axis."
matplotlib.pyplot.xlabel(s, *args, **kwargs)

# "Set the y axis label of the current axis."
matplotlib.pyplot.ylabel(s, *args, **kwargs)

# "Set a title of the current axes."
matplotlib.pyplot.title(s, *args, **kwargs)


Command:

$ cat testdarkbackground.py


Result:

#!/usr/local/bin/python

import numpy as np
import matplotlib.pyplot as plt

plt.style.use('dark_background')

L = 6
x = np.linspace(0, L)
ncolors = len(plt.rcParams['axes.prop_cycle'])
shift = np.linspace(0, L, ncolors, endpoint=False)
for s in shift:
    plt.plot(x, np.sin(x + s), 'o-')
plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.title('title')

plt.show()


Command:

$ python testdarkbackground.py


Graphical output:

Python: Matplotlib: Scatter Plot Example

Noteworthy:

# "Random values in a given shape."
numpy.random.rand(d0, d1, ..., dn)

# "Make a scatter plot of x vs y, where x and y are sequence like objects of the same length."
matplotlib.pyplot.scatter(x, y, s=20, c=None, marker='o', cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None, hold=None, data=None, **kwargs)


Command:

$ cat testscatterplot.py


Result:

#!/usr/local/bin/python

import matplotlib.pyplot as plt
from numpy.random import rand
a = rand(100)
b = rand(100)
plt.scatter(a,b)
plt.show()


Command:

$ python testscatterplot.py


Graphical output:

Python: Matplotlib: Histogram Example

Noteworthy:

# "Draw random samples from a normal (Gaussian) distribution."
# 正規分布(ガウス分布)からランダムにサンプルして線を描く。
numpy.random.normal(loc=0.0, scale=1.0, size=None)

# "Plot a histogram"
# ヒストグラムをプロット(描写)する。
matplotlib.pyplot.hist(x, bins=10, range=None, normed=False, weights=None, cumulative=False, bottom=None, histtype='bar', align='mid', orientation='vertical', rwidth=None, log=False, color=None, label=None, stacked=False, hold=None, data=None, **kwargs)


Command:

$ cat testhistogram.py


Result:

#!/usr/local/bin/python

import matplotlib.pyplot as plt
from numpy.random import normal,rand
x = normal(size=200)
plt.hist(x,bins=30)
plt.show()


Command:

$ python testhistogram.py


Graphical output:




Python: Matplotlib: Line Plot Example

Noteworthy:

# "Return evenly spaced numbers over a specified interval."
# 等間隔に並べた数字を返す。
numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)

# "Calculate the exponential of all elements in the input array."
# 指数の計算
numpy.exp(x[, out]) = <ufunc 'exp'>

# "Display a figure."
# フィギュアを表示する。
matplotlib.pyplot.show(*args, **kw)


Command:

$ cat testlineplot.py


Result:

#!/usr/local/bin/python

import matplotlib.pyplot as plt
import numpy as np
a = np.linspace(0,10,100)
b = np.exp(-a)
plt.plot(a,b)
plt.show()


Graphical output: