绘制一个3D立方体并在其旁边写文字
我有问题。我有一个dataframe df
。这包含长度
,width
,height
和卷
之类的规范。 我想计算min
,max
和Mean
值,并使用Cube以图形方式显示它们。 为此,您可以在下面看到以下有关我希望它看起来的说明。我想显示一个带有文字的立方体。此外,长度
,width
,height
。如何在Matplotlib的帮助下以图形方式表示该立方体?
数据框
length width height volume
0 1.5 1.5 1.5 0.15
1 0.4 0.8 0.6 0.85
2 4.3 8.5 3.5 1.15
3 3.3 4.5 2.4 0.02
length width height volume
mean 2.375000 3.825000 2.000000 0.542500
min 0.400000 0.800000 0.600000 0.020000
max 4.300000 8.500000 3.500000 1.150000
的数据框架代码
import pandas as pd
d = {
"length": [1.5, 0.4, 4.3, 3.3],
"width": [1.5, 0.8, 8.5, 4.5],
"height": [1.5, 0.6, 3.5, 2.4],
"volume": [0.15, 0.85, 1.15, 0.02],
}
df = pd.DataFrame(data=d)
cube
# Import libraries
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
# Create axis
axes = [5, 5, 5]
# Create Data
data = np.ones(axes, dtype=np.bool)
# Controll Tranperency
alpha = 0.9
# Control colour
colors = np.empty(axes + [4], dtype=np.float32)
colors[:] = [0.9, 0.9, 0.9, alpha] # red
# Plot figure
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Voxels is used to customizations of the
# sizes, positions and colors.
ax.voxels(data, facecolors=colors)
I have a problem. I have a dataframe df
. This contains specifications like length
, width
, height
and the volume
.
I would like to calculate the min
, max
and mean
values and display them graphically with a cube.
For this purpose, you can see below the following illustration of how I would like it to look. I would like to display a cube with texts next to it. In addition, there should be an additional line next to the length
, width
, height
. How can I represent this cube graphically with the help of Matplotlib?
Dataframe
length width height volume
0 1.5 1.5 1.5 0.15
1 0.4 0.8 0.6 0.85
2 4.3 8.5 3.5 1.15
3 3.3 4.5 2.4 0.02
length width height volume
mean 2.375000 3.825000 2.000000 0.542500
min 0.400000 0.800000 0.600000 0.020000
max 4.300000 8.500000 3.500000 1.150000
Code for dataframe
import pandas as pd
d = {
"length": [1.5, 0.4, 4.3, 3.3],
"width": [1.5, 0.8, 8.5, 4.5],
"height": [1.5, 0.6, 3.5, 2.4],
"volume": [0.15, 0.85, 1.15, 0.02],
}
df = pd.DataFrame(data=d)
Cube
# Import libraries
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
# Create axis
axes = [5, 5, 5]
# Create Data
data = np.ones(axes, dtype=np.bool)
# Controll Tranperency
alpha = 0.9
# Control colour
colors = np.empty(axes + [4], dtype=np.float32)
colors[:] = [0.9, 0.9, 0.9, alpha] # red
# Plot figure
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Voxels is used to customizations of the
# sizes, positions and colors.
ax.voxels(data, facecolors=colors)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论