Search code examples
pythonmatplotlibplotmatplotlib-3d

3D plots in Python


How could I plot the following data in 3 dimensions? (apparently, there are more than that!)

data = [[10, 10, 0.84496124031007758],
        [10, 20, 0.87209302325581395],
        [10, 30, 0.88139534883720927],
        [20, 10, 0.86201550387596892],
        [20, 20, 0.87441860465116272],
        [20, 30, 0.88992248062015500],
        [30, 10, 0.87984496124031009],
        [30, 20, 0.89922480620155043],
        [30, 30, 0.92015503875968996]]

Solution

  • what kind of plot are you trying to get? Try this for a scatter plot. I'm also assuming your data is listed in x,y,z lists in your question.

    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    
    x, y, z = zip(*data)
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.scatter(x,y,z)
    plt.show()