mplfinance icon indicating copy to clipboard operation
mplfinance copied to clipboard

missing from current font. FigureCanvasAgg.draw(self)

Open adsian opened this issue 1 year ago • 0 comments

Ask anything you want about mplfinance usage, project philosophy and/or priorities, or anything else related to mplfinance.

import mplfinance as mpf
import pandas as pd
import matplotlib.pyplot as plt

# 设置 matplotlib 的默认字体为 SimHei
plt.rcParams['font.family'] = 'SimHei'

# 假设您有以下 DataFrame 形式的数据
df = pd.DataFrame({
    'Date': ['2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04', '2023-01-05', '2023-01-06', '2023-01-07'],
    'Open': [100, 102, 98, 101, 99, 103, 104],
    'High': [101, 104, 100, 102, 101, 105, 106],
    'Low': [99, 100, 97, 99, 97, 101, 102],
    'Close': [100, 101, 99, 100, 100, 103, 104]
})

# 将日期列转换为 datetime 格式并设置为索引
df['Date'] = pd.to_datetime(df['Date'])
df.set_index('Date', inplace=True)

# 绘制 K 线图
mpf.plot(df, type='candle', figsize=(12, 6), title='K 线图')

error:

/Users/roger/Applications/PyCharm Professional Edition.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend/backend_interagg.py:80: UserWarning: Glyph 32447 (\N{CJK UNIFIED IDEOGRAPH-7EBF}) missing from current font. FigureCanvasAgg.draw(self) /Users/roger/Applications/PyCharm Professional Edition.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend/backend_interagg.py:80: UserWarning: Glyph 22270 (\N{CJK UNIFIED IDEOGRAPH-56FE}) missing from current font. FigureCanvasAgg.draw(self)

question:

how can I generate pics with chinese characters with local font settings? (ignore environments)

adsian avatar Jul 25 '24 03:07 adsian