I couldn’t quite get the graph to represent what I wanted, but here is the attempt regardless. I am not annotating it much more than this, as you are welcome to check out the hand drawn reference

Code

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
 
# Parameters for the cube and partitioning
a, b = 0, 2  # x-range
c, d = 0, 2  # y-range
h = 2  # height for z
n = 5  # Number of slabs
delta_y = (d - c) / n  # Width of each slab
 
# Create the figure and 3D axis
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection='3d')
 
# Define vertices of the cube at the corners
x_corners = [a, b, b, a, a, b, b, a]
y_corners = [c, c, d, d, c, c, d, d]
z_corners = [0, 0, 0, 0, h, h, h, h]
 
# Plot the partitioned 3D blocks along the y-axis
for i in range(1, n+1):
    y_i = c + i * delta_y
    y_i_1 = c + (i - 1) * delta_y
    
    # Vertices of the 3D block (miniature block partition)
    verts_block = [
        [[a, y_i_1, 0], [b, y_i_1, 0], [b, y_i_1, h], [a, y_i_1, h]],  # bottom face
        [[a, y_i, 0], [b, y_i, 0], [b, y_i, h], [a, y_i, h]],  # top face
        [[a, y_i_1, 0], [a, y_i, 0], [a, y_i, h], [a, y_i_1, h]],  # left face
        [[b, y_i_1, 0], [b, y_i, 0], [b, y_i, h], [b, y_i_1, h]]  # right face
    ]
    
    # Plot the block as a 3D rectangle
    ax.add_collection3d(Poly3DCollection(verts_block, facecolors='purple', linewidths=1, edgecolors='k', alpha=0.5))
    
    # Label y_i-1 and y_i on the x-axis for the block
    if i == 2:  # Example block to label
        ax.text(a, y_i_1 - 0.1, 0, '$y_{i-1}$', color='black', fontsize=10)
        ax.text(a, y_i + 0.1, 0, '$y_i$', color='black', fontsize=10)
        
# Add labels for the start (c = y_0) and end (d = y_n) of the cube
ax.text(b + 0.1, c, 0, '$c = y_0$', color='black', fontsize=12)
ax.text(b + 0.1, d, 0, '$d = y_n$', color='black', fontsize=12)
 
# Set labels and titles
ax.set_xlabel('X axis')
ax.set_ylabel('Y axis')
ax.set_zlabel('Z axis')
ax.set_title('Blocky 3D Partition of Cube with Labels for $y_{i-1}$ and $y_i$')
 
# Remove lines connecting cube corners
ax.grid(False)
 
# Set axis limits to match a cube shape
ax.set_xlim([a, b])
ax.set_ylim([c, d])
ax.set_zlim([0, h])
 
# Display the plot
plt.show()