3D Bar Chart

Quarterly Sales 3D

3D bar chart showing quarterly sales performance across product categories

Output
Quarterly Sales 3D
Python
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure(figsize=(12, 8), facecolor='white')
ax = fig.add_subplot(111, projection='3d')
ax.set_facecolor('white')

# Data: 4 quarters, 5 products
quarters = 4
products = 5
xpos = np.arange(quarters)
ypos = np.arange(products)
xpos, ypos = np.meshgrid(xpos, ypos)
xpos = xpos.flatten()
ypos = ypos.flatten()
zpos = np.zeros_like(xpos)

dx = dy = 0.6
dz = np.array([45, 62, 38, 71, 55, 48, 73, 52, 68, 41,
               59, 66, 44, 78, 63, 51, 69, 57, 82, 47])

# Gradient from coral to magenta
colors = plt.cm.colors.LinearSegmentedColormap.from_list('', ['#F5B027', '#F5276C'])
bar_colors = [colors(v/max(dz)) for v in dz]

ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color=bar_colors, alpha=0.9, edgecolor='#000000', linewidth=0.3)

ax.set_xlabel('Quarter', fontsize=11, color='#1f2937', labelpad=10)
ax.set_ylabel('Product', fontsize=11, color='#1f2937', labelpad=10)
ax.set_zlabel('Sales (K)', fontsize=11, color='#1f2937', labelpad=10)
ax.set_title('Quarterly Sales Performance', fontsize=14, color='#1f2937', fontweight='bold', pad=20)

ax.set_xticks([0, 1, 2, 3])
ax.set_xticklabels(['Q1', 'Q2', 'Q3', 'Q4'])
ax.set_yticks([0, 1, 2, 3, 4])
ax.set_yticklabels(['A', 'B', 'C', 'D', 'E'])
ax.tick_params(colors='#000000', labelsize=9)

ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#000000')
ax.yaxis.pane.set_edgecolor('#000000')
ax.zaxis.pane.set_edgecolor('#000000')
ax.grid(True, alpha=0.5, linewidth=0.5)
ax.xaxis._axinfo['grid']['color'] = '#000000'
ax.yaxis._axinfo['grid']['color'] = '#000000'
ax.zaxis._axinfo['grid']['color'] = '#000000'
ax.xaxis._axinfo['tick']['color'] = '#000000'
ax.yaxis._axinfo['tick']['color'] = '#000000'
ax.zaxis._axinfo['tick']['color'] = '#000000'


ax.xaxis.line.set_color('#000000')
ax.yaxis.line.set_color('#000000')
ax.zaxis.line.set_color('#000000')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

3D Charts

Did this help you?

Support PyLucid to keep it free & growing

Support