Colouring in between two lines in 3D plot
<p>I am trying the fill the space between my lines in 3D. </p>

<p>I have the following code:</p>

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

class plotting3D(object):
    """
    Class to plot 3d
    """

    def __init__(self):
        pass

    def cc(self, arg):
        return colorConverter.to_rgba(arg, alpha=0.6)

    def poly3d(self, df):
        """
        Method to create depth of joints plot for GP regression.
        """
        fig = plt.figure(figsize=(10,10))
        ax = fig.gca(projection='3d')

        which_joints = df.columns
        dix = df.index.values
        zs = [1,4]
        verts = []
        for j in which_joints:
            verts.append(list(zip(dix,df[j])))

        poly = PolyCollection(verts,facecolors=[self.cc('r'), self.cc('g')])
        poly.set_alpha(0.6)
        ax.add_collection3d(poly, zs=zs, zdir='y')

        ax.set_ylim([0, 5])
        ax.set_zlim([0, 20])
        ax.set_xlim([0,dix[-1]])
        ax.grid(False)
        ax.set_xlabel('X')
        ax.set_ylabel('Y')
        ax.set_zlabel('Z')

        plt.show()
</code></pre>

<p>Some synthetic data:</p>

<pre><code>k= pd.DataFrame(20*np.random.rand(10,2),columns=['foot','other_foot'])
</code></pre>

<p>Produces this:</p>

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

<p>Now I want to fill the space between the lines and say <code>z=-30</code> NOT <code>z=0</code> which is what I am trying to change.</p>

<p><code>df.index.values</code> take a values between <code>0</code> and say <code>1000</code>. And the <code>ang</code> dataframe has values ranging from <code>-30</code> to <code>10</code>.</p>

<p>Hence, I am trying to produce an offset version of this:</p>

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

<p>Another solution to my suggestion in the comments is to use <code>fill_between</code>; there you have the possibility to set the lower boundary. <code>fill_between</code> returns a <code>PolyCollection</code>, so you can add it to the <code>3d</code> figure similar to what you are doing now:</p>

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

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

# +/- your data:
z = [0,10,10,-20,10,0]
x = [0,1000,1500,2500,3000,3500]

ax.add_collection3d(plt.fill_between(x,z,0),   zs=1, zdir='y') # lower boundary z=0
ax.add_collection3d(plt.fill_between(x,z,-30), zs=5, zdir='y') # lower boundary z=-30

ax.set_ylim([0, 5])
ax.set_zlim([-30, 20])
ax.set_xlim([0,3500])
</code></pre>

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

python matplotlib