On Mon, Feb 7, 2011 at 5:02 AM, Paul Leopardi <paul.leopardi@iinet.net.au> wrote:

Paul,

As formatted, the code would not run. I presume that everything after "for j in range(0,M):" should be indented? When I did that and ran it in ipython, I could not reproduce your problem. What version of matplotlib are you running?

Ben Root

Hi all,

On Sun, 6 Feb 2011 03:54:48 PM Paul Leopardi wrote:I have appended an entire example script, below.

> I'm having trouble using multiple figures with mplot3d.

The script incrementally plots 3 curves, one in each of 3 figure windows. The

trouble is, once Figure 2 has finished plotting, the curve for Figure 1

disappears and is replaced by the curve for Figure 2, with the axes for Figure

1; once Figure 3 has finished plotting, the curves for Figures 1 and 2

disappear and are replaced by the curve for Figure 3, with the axes for Figure

1 and Figure 2, respectively.

The original code was written with incremental plotting because the points

took a long time to calculate. Without incremental plotting, the figures

stayed blank for a long time. The script below is very similar to my original

script, but does not depend on my GluCat library.

Best, Paul

---

# -*- coding: utf-8 -*-

# Imports needed for array calculation and plotting.

from numpy import array, floor, random, empty, cos, pi

from mpl_toolkits.mplot3d import Axes3D# Constants to control the plotting.

import matplotlib.pyplot as plt

C=3 # Number of curves to plot.

P=1000 # Number of points overall.

R=2 # Scaling constant to use.

N=25 # Number of points in a curve segment.

M=P/N

# Array of points.

x=empty((3,P))

rgb=empty((3))

# Initial point.

# Plot C curves.

for i in xrange(0,C):

x0=random.randn(3)

# Plot a curve using a random bivector in R_{5,0}

# with appropriate scaling.

w=random.randn(3) * 2*pi*R/P

# ax=Axes3D(fig)

# Use a new figure for each curve.

fig=plt.figure(figsize=(15,12))

ax = fig.gca(projection='3d')# Coordinate limits to determine the colour of the first curve segment.

plt.show()

minx=array([-x0[0],x0[1],-x0[2]])

maxx=minx.copy()

# Find N points forming a curve segment by

# Split the curve into M segments, each with an appropriate colour.

for j in range(0,M):

# exponentiating w*k for k from j*N to (j+1)*N-1.

abot=j*N

atop=abot+N

for k in xrange(abot,atop):

for h in range(0,3):

x[h,k]=x0[h]+cos(w[h]*k)

amid=floor((abot+atop)/2)

# Determine the colour of the curve segment.

for h in range(0,3):

sign=(-1)**(h+1)

minx[h]=min(minx[h],min(sign*x[h,abot:atop]))

maxx[h]=max(maxx[h],max(sign*x[h,abot:atop]))

rgb[h]=max(0.0,min((sign*x[h,amid]-minx[h])/(maxx[h]-minx[h]),1.0))

# Plot the curve segment using the chosen colour.

alow=(abot-1 if j>0 else abot)

ax.plot(x[0,alow:atop],x[1,alow:atop],x[2,alow:atop],c=rgb.tolist())

plt.draw()

plt.show()

Paul,

As formatted, the code would not run. I presume that everything after "for j in range(0,M):" should be indented? When I did that and ran it in ipython, I could not reproduce your problem. What version of matplotlib are you running?

Ben Root