loop through numpy arrays, plot all arrays to single figure (matplotlib)
<p>the functions below each plot a single numpy array<br /> 
plot1D, plot2D, and plot3D take arrays with 1, 2, and 3 columns, respectively</p>

<pre><code>import numpy as np 
import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D


def plot1D(data):
    x=np.arange(len(data))
    plot2D(np.hstack((np.transpose(x), data)))

def plot2D(data):
    # type: (object) -&gt; object
    #if 2d, make a scatter
    plt.plot(data[:,0], data[:,1], *args, **kwargs)

def plot3D(data):
    #if 3d, make a 3d scatter
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.plot(data[:,0], data[:,1], data[:,2], *args, **kwargs)
</code></pre>

<p>I would like the ability to input a list of 1, 2, or 3d arrays and plot all arrays from the list onto one figure</p>

<p>I have added the looping elements, but am unsure how hold a figure and add additional plots...</p>

<pre><code>def plot1D_list(data):
    for i in range(0, len(data)):
        x=np.arange(len(data[i]))
        plot2D(np.hstack((np.transpose(x), data[i])))

def plot2D_list(data):
    # type: (object) -&gt; object
    #if 2d, make a scatter
    for i in range(0, len(data)):
        plt.plot(data[i][:,0], data[i][:,1], *args, **kwargs)

def plot3D_list(data):
    #if 3d, make a 3d scatter
    for i in range(0, len(data)):
        fig = plt.figure()
        ax = fig.add_subplot(111, projection='3d')
        ax.plot(data[i][:,0], data[i][:,1], data[i][:,2], *args, **kwargs)
</code></pre>

<p>To plot multiple data sets on the same axes, you can do something like this:</p>

<pre><code>def plot2D_list(data,*args,**kwargs):
    # type: (object) -&gt; object
    #if 2d, make a scatter
    n = len(data)
    fig,ax = plt.subplots() #create figure and axes
    for i in range(n):
        #now plot data set i
        ax.plot(data[i][:,0], data[i][:,1], *args, **kwargs)
</code></pre>

<p>Your other functions can be generalised in the same way. Here's an example of using the above function with a 5 sets of randomly generated x-y coordinates, each with length 100 (each of the 5 data sets appears as a different color):</p>

<pre><code>import numpy as np

X = np.random.randn(5,100,2)
plot2D_list(X,'o')
plt.show()
</code></pre>

<p><a href="http://i.stack.imgur.com/gm2eK.png" rel="nofollow"><img src="http://i.stack.imgur.com/gm2eK.png" alt="enter image description here"></a></p>

python arrays numpy matplotlib