Dear Matplotlib folks,
I want to plot all paths of a simple random walk and wrote the following
recursive program based on the Path tutorial .
import matplotlib.pyplot as plt
from matplotlib.path import Path
import matplotlib.patches as patches
def draw(a, b, c, d):
verts = [
codes = [
path = Path(verts, codes)
patch = patches.PathPatch(path)
def irrpfad(a, b):
if a < length:
draw(a, b, a + 1., b + 1.)
draw(a, b, a + 1., b - 1.)
irrpfad(a + 1, b + 1)
irrpfad(a + 1, b - 1)
length = 5 # 20 not possible to run
fig = plt.figure()
ax = fig.add_subplot(111)
Using 20 for `length` stalls my system and the memory used seems to be
over 1 GB. I guess this is what you guess using something recursive.
What optimizations are there. I am drawing each line after another so
probably too many separate paths instead of one. Being a Python noob I
do not know if I can append something to a path. Looking at the API
documentation  I did not see such a method.
Being also new to Matplotlib I may have also overlooked more appropriate
So to summarize my message,
1. How can I add lines to a path?
2. Are recursive functions bad in Python/Matplotlib?
3. Are there better approaches?
Please find the source also attached. I am using python-matplotlib
1.0.1-2 from Debian Sid/unstable.
srw.py (903 Bytes)