Python plot 3d surface drawing
Question: I have a function `F = 0.8*X+0.6*Y+0.9*Z` But my problem is X Y and Z related
to each other. `X+Y+Z = 1`. The values and intervals should be like:

    
    
    X = np.arange(0,1,0.01)
    Y = np.arange(0,(1-X),0.01)
    Z = 1-(X+Y)
    

Could you please give a simple way of doing this in Python. Thanks in advance.


Answer: If you want to do a surface plot in matplotlib your x, y and z arrays should
be 2D arrays. If interval of your variables depends on each other, you can
define your variables in terms of variables whose intervals is independent of
each other like u and v in here.

    
    
    from mpl_toolkits.mplot3d import Axes3D
    from matplotlib import cm
    from matplotlib.colors import Normalize
    import matplotlib.pyplot as plt
    import numpy as np
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    
    u = np.linspace(0, 1, 100)
    v = np.linspace(1, 0, 100)
    
    x = np.outer(np.ones_like(u), v)
    y = np.outer(v, u)
    z = 1 - x - y
    f = 0.8*x + 0.6*y + 0.9*z
    
    norm = Normalize (f.min(), f.max())
    m = plt.cm.ScalarMappable()
    m.set_array([])
    fcolors = m.to_rgba(f)
    
    ax.view_init(azim=45)
    ax.plot_surface(x, y, z, norm=norm, rstride=2, cstride=2, facecolors=fcolors, shade=False)
    
    plt.show()
    

[![enter image description
here](http://i.stack.imgur.com/XQBC1.png)](http://i.stack.imgur.com/XQBC1.png)

