matplotlib中文绘图
1 、在 /usr/share/fonts/下载字体 2、 fc-list :lang=zh 查看字体 3、使用 import matplotlib import numpy as np import pandas as pd import matplotlib.pyplot as plt from matplotlib import font_manager font_manager.fontManager.addfont ( "/usr/share/fonts/SourceHanSansCN-Normal.otf" ) plt.rcParams [ 'font.sans-serif' ] = [ 'Source Han Sans CN' ] ### 解决中文乱码 plt.rcParams [ 'axes.unicode_minus' ] = False # fname 为 你下载的字体库路径,注意 SourceHanSansSC-Bold.otf 字体的路径 dataset = pd.read_csv ( 'data/Rabies.csv' , header = 0 , index_col = 0 ) dataset.index=pd.to_datetime ( dataset.index ) dataset [ ' 狂犬疫苗接种量 ' ] .plot () dataset.plot () plt.show () import matplotlib.pyplot as plt from matplotlib.font_manager import FontProperties from plotnine import ggplot, aes, geom_bar, coord_flip, theme, element_text font = FontProperties( fname = "/usr/share/fonts/SourceHanSansCN-Regular.otf" ) ( ggplot(top_vaccines.reset_index(), aes( x = 'ym_mc' , y = &