Spaces:
Runtime error
Runtime error
import matplotlib.pyplot as plt | |
import numpy as np | |
def create_multiplication_table(number: int, max_multiplier: int = 12) -> plt.Figure: | |
"""Create a visual multiplication table.""" | |
fig, ax = plt.subplots(figsize=(8, 6)) | |
multipliers = np.arange(1, max_multiplier + 1) | |
results = number * multipliers | |
bars = ax.bar(multipliers, results, color='skyblue', alpha=0.7, edgecolor='navy') | |
for bar, result in zip(bars, results): | |
height = bar.get_height() | |
ax.text(bar.get_x() + bar.get_width()/2., height + max(results) * 0.01, | |
f'{result}', ha='center', va='bottom', fontweight='bold') | |
ax.set_xlabel('Multiplier', fontsize=12) | |
ax.set_ylabel('Result', fontsize=12) | |
ax.set_title(f'Multiplication Table for {number}', fontsize=14, fontweight='bold') | |
ax.grid(True, alpha=0.3) | |
ax.set_xticks(multipliers) | |
return fig | |