How to scale the voxel-dimensions with Matplotlib?

前端 未结 2 1422
隐瞒了意图╮
隐瞒了意图╮ 2021-01-23 07:08

Want to scale the voxel-dimensions with Matplotlib. How can I do this?

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D         


        
2条回答
  •  时光说笑
    2021-01-23 07:35

    You can pass custom coordinates to the voxels function: API reference.

    import numpy as np
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    # Make grid
    test2 = np.zeros((6, 6, 6))
    # Activate single Voxel
    test2[1, 0, 4] = True
    
    # Custom coordinates for grid
    x,y,z = np.indices((7,7,7))/2
    
    # Pass the custom coordinates as extra arguments
    ax.voxels(x, y, z, test2, edgecolor="k")
    ax.set_xlabel('0 - Dim')
    ax.set_ylabel('1 - Dim')
    ax.set_zlabel('2 - Dim')
    
    plt.show()
    

    Which would yield:

提交回复
热议问题