UserWarning: Glyph 39006 (\N{CJK UNIFIED IDEOGRAPH-985E}) missing from current font. fig.canvas.print_figure(bytes_io, **kw)
UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from current font. fig.canvas.print_figure(bytes_io, **kw)
Output is truncated. View as a [scrollable element](command:cellOutput.enableScrolling?44759503-8355-41d4-aad1-d64a9ecd7a1e) or open in a [text editor](command:workbench.action.openLargeOutput?44759503-8355-41d4-aad1-d64a9ecd7a1e). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...
我們透過 font_manager 查看目前有安裝哪些字體
from matplotlib.font_manager import FontManager
fm = FontManager()
mat_fonts = set(f.name for f in fm.ttflist)
print(mat_fonts)
在輸出影像時修改,指定已安裝的字體, mac 大部分都有Arial Unicode Ms
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['Arial Unicode Ms']
可以用這個測試
plt.figure(figsize=(10, 6))
plt.bar(['A', 'B', 'C'], [10, 20, 15])
plt.title('中文字測試', fontsize=16) # 標題中應用中文字體
plt.xlabel('類別', fontsize=12) # 標籤中應用中文字體
plt.ylabel('數量', fontsize=12) # 標籤中應用中文字體
plt.show()
成功了!