绘制一个3D立方体并在其旁边写文字

发布于 2025-02-08 08:10:37 字数 1969 浏览 0 评论 0原文

我有问题。我有一个dataframe df。这包含长度widthheight之类的规范。 我想计算minmaxMean值,并使用Cube以图形方式显示它们。 为此,您可以在下面看到以下有关我希望它看起来的说明。我想显示一个带有文字的立方体。此外,长度widthheight 。如何在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)

What I want
enter image description here

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)

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文