fix(bug): remove local matplotlib import shadowing global plt in stats

This commit is contained in:
Xiaolan Bot
2026-02-23 01:37:58 +08:00
parent 1d0fe1cdf3
commit ebfc342736

View File

@@ -518,7 +518,7 @@ async def stats(update: Update, context: CallbackContext):
try: try:
theme_colors = ['#3B82F6', '#10B981', '#F59E0B', '#EF4444', '#8B5CF6', '#EC4899', '#14B8A6', '#F97316', '#6366F1', '#84CC16'] theme_colors = ['#3B82F6', '#10B981', '#F59E0B', '#EF4444', '#8B5CF6', '#EC4899', '#14B8A6', '#F97316', '#6366F1', '#84CC16']
if len(category_costs) > len(theme_colors): if len(category_costs) > len(theme_colors):
import matplotlib.pyplot as plt # 移除导致遮蔽的局部 import直接使用全局的 matplotlib 和 plt
extra_colors = [matplotlib.colors.to_hex(c) for c in plt.get_cmap('tab20').colors] extra_colors = [matplotlib.colors.to_hex(c) for c in plt.get_cmap('tab20').colors]
theme_colors.extend(extra_colors) theme_colors.extend(extra_colors)