使用dataframe_image 方法 但是图片生成后无法显示中文
import requests
import pandas as pd
import UnixDataTime
import dataframe_image as dfi
import matplotlib as plt
from matplotlib.font_manager import FontProperties
# 尝试的方法1
# plt.rcParams['font.family'] = 'sans-serif'
# plt.rcParams['font.sans-serif'] = ['SimHei']
# plt.rcParams['axes.unicode_minus'] = False
# 尝试的方法2
# FontProperties(fname='/Users/fang/PycharmProjects/GYPushDingDataBike/SimHei.ttf')
数据放在listAreaBikeData列表里,转换成DataFrame
df = pd.DataFrame(listAreaBikeData, columns=columnHead)
# 使用dataframe_image模块的export方法截图设置为matplotlib
dfi.export(obj=df, filename=imgPath, table_conversion='matplotlib')
运行结果正常,但是就是提示无加载字体
/opt/anaconda3/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:203: RuntimeWarning: Glyph 33829 missing from current font.
font.set_text(s, 0, flags=flags)
/opt/anaconda3/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:203: RuntimeWarning: Glyph 36742 missing from current font.
font.set_text(s, 0, flags=flags)
/opt/anaconda3/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 29575 missing from current font.
font.set_text(s, 0.0, flags=flags)
/opt/anaconda3/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:203: RuntimeWarning: Glyph 29575 missing from current font.
font.set_text(s, 0, flags=flags)
/opt/anaconda3/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 35266 missing from current font.
font.set_text(s, 0.0, flags=flags)
/opt/anaconda3/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:203: RuntimeWarning: Glyph 35266 missing from current font.
font.set_text(s, 0, flags=flags)
/opt/anaconda3/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 22806 missing from current font.
font.set_text(s, 0.0, flags=flags)
/opt/anaconda3/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:203: RuntimeWarning: Glyph 22806 missing from current font.
font.set_text(s, 0, flags=flags)
/opt/anaconda3/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 20840 missing from current font.
font.set_text(s, 0.0, flags=flags)
/opt/anaconda3/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:203: RuntimeWarning: Glyph 20840 missing from current font.
font.set_text(s, 0, flags=flags)
我搜了CSDN很多相关的方法,也下载了SimHei.ttf字体放在了指定的文件下,都是无效的
显示中文正常