如何使用Matplotlib缩放体素尺寸? [英] How to scale the voxel-dimensions with Matplotlib?
本文介绍了如何使用Matplotlib缩放体素尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想用Matplotlib缩放体素尺寸.我该怎么办?
将 numpy 导入为 np导入matplotlib.pyplot作为plt从mpl_toolkits.mplot3d导入Axes3D无花果= plt.figure()ax = fig.gca(投影='3d')#制作网格test2 = np.zeros((6, 6, 6))#激活单个体素test2 [1,0,4] = Trueax.voxels(test2, edgecolor="k")ax.set_xlabel('0 - Dim')ax.set_ylabel('1 - Dim')ax.set_zlabel('2 - Dim')plt.show()
取而代之的是位置 (1,0,4) 上的体素.我想将其缩放为(0.5,0,2).
解决方案
您可以将自定义坐标传递给 voxels
函数:
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
fig = plt.figure()
ax = fig.gca(projection='3d')
# Make grid
test2 = np.zeros((6, 6, 6))
# Activate single Voxel
test2[1, 0, 4] = True
ax.voxels(test2, edgecolor="k")
ax.set_xlabel('0 - Dim')
ax.set_ylabel('1 - Dim')
ax.set_zlabel('2 - Dim')
plt.show()
Instead the voxel on position (1,0,4). I want to scale it on (0.5,0,2).
解决方案
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:
这篇关于如何使用Matplotlib缩放体素尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文