Python annotating points in a 3D scattter plot

前端 未结 2 1386
没有蜡笔的小新
没有蜡笔的小新 2021-01-25 18:11

I want to give labels to each point (3D) in my data and the labels (the labels are keys in a dictionary) :

l = list(dictionary.keys())
#transform the array to a          


        
2条回答
  •  醉话见心
    2021-01-25 18:45

    You could add text to each of your points as follows:

    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    
    ax3d = plt.figure().gca(projection='3d')
    
    arrayx = np.array([[0.7], [7.1], [7.5], [0.6], [0.5], [0.00016775708773695687]])
    arrayy = np.array([[0.1], [2], [3], [6], [5], [16775708773695687]])
    arrayz = np.array([[1], [2], [3], [4], [5], [6]])
    
    labels = ['one', 'two', 'three', 'four', 'five', 'six']
    
    arrayx = arrayx.flatten()
    arrayy = arrayy.flatten()
    arrayz = arrayz.flatten()
    
    ax3d.scatter(arrayx, arrayy, arrayz)
    
    #give the labels to each point
    for x, y, z, label in zip(arrayx, arrayy, arrayz, labels):
        ax3d.text(x, y, z, label)
    
    plt.title("Data")
    plt.show()
    

    This would give you the following output:

提交回复
热议问题