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)

