
Optuna使用詳解與案例分析
為了在Matplotlib中顯示中文,需要設置字體為支持中文的字體。例如,可以使用’Arial Unicode MS’字體:
a = sorted([f.name for f in matplotlib.font_manager.fontManager.ttflist])
for i in a:
print(i)
plt.rcParams['font.family'] = 'Arial Unicode MS'
通過設置plt.rcParams['font.family']
為’Arial Unicode MS’,可以確保圖表中的中文顯示正常。
了解Matplotlib中默認字體及字體庫路徑對于自定義字體設置非常重要。
我們可以通過以下代碼查看Matplotlib中默認的字體列表:
import matplotlib.pyplot as plt
#打印當前設置的字體族中的第一個字體的名稱
print(plt.rcParams[