Skip to content

Commit

Permalink
async preset_fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenliang123 committed Nov 28, 2024
1 parent 510763d commit 612a11b
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions api/core/tools/provider/builtin/chart/chart.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties, fontManager
from threading import Thread

from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController


def set_chinese_font():
from matplotlib.font_manager import FontProperties, fontManager

to_find_fonts = [
"PingFang SC",
"SimHei",
Expand All @@ -24,13 +24,20 @@ def set_chinese_font():
return FontProperties()


# use non-interactive backend to prevent `RuntimeError: main thread is not in main loop`
matplotlib.use("Agg")
# use a business theme
plt.style.use("seaborn-v0_8-darkgrid")
plt.rcParams["axes.unicode_minus"] = False
font_properties = set_chinese_font()
plt.rcParams["font.family"] = font_properties.get_name()
def preset_fonts():
import matplotlib
import matplotlib.pyplot as plt

# use non-interactive backend to prevent `RuntimeError: main thread is not in main loop`
matplotlib.use("Agg")
# use a business theme
plt.style.use("seaborn-v0_8-darkgrid")
plt.rcParams["axes.unicode_minus"] = False
font_properties = set_chinese_font()
plt.rcParams["font.family"] = font_properties.get_name()


Thread(target=preset_fonts, name="preset_fonts", daemon=True).start()


class ChartProvider(BuiltinToolProviderController):
Expand Down

0 comments on commit 612a11b

Please sign in to comment.