glyph 24230 missing from current font.解决-matplotlib绘图踩坑
2020-07-24 15:29
363 查看
问题描述
用matplotlib绘图的时候,title是中文 报错如下:
D:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:100: RuntimeWarning: Glyph 24230 missing from current font. font.set_text(s, 0.0, flags=flags) D:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:120: RuntimeWarning: Glyph 38388 missing from current font. font.set_text(s, 0.0, flags=flags)
解决方案
在引入matplotlib库后作如下操作
import matplotlib.pyplot as plt plt.rcParams[‘font.sans-serif’]=[‘SimHei’] #用来正常显示中文标签 plt.rcParams[‘axes.unicode_minus’]=False #用来正常显示负号
Example
## 没有写出导入数据部分 import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt from matplotlib.patches import Rectangle,Circle from matplotlib.collections import PatchCollection %matplotlib inline plt.rcParams['font.sans-serif']=["SimHei"] #用来正常显示中文标签 plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 data = pd.read_csv('hotel_bookings.csv') ## https://www.kaggle.com/search?q=hotel+booking data_new = data data_new["adr_pp"] = data_new["adr"] / (data_new["adults"] + data_new["children"]) full_data_guests = data_new.loc[data_new["is_canceled"] == 0] # only actual gusts room_prices = full_data_guests[["hotel", "reserved_room_type", "adr_pp"]].sort_values("reserved_room_type") room_price_monthly = full_data_guests[["hotel", "arrival_date_month", "adr_pp"]].sort_values("arrival_date_month") ordered_months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] month_che = ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月", ] for en, che in zip(ordered_months, month_che): room_price_monthly["arrival_date_month"].replace(en, che, inplace=True) room_price_monthly["arrival_date_month"] = pd.Categorical(room_price_monthly["arrival_date_month"], categories=month_che, ordered=True) room_price_monthly["hotel"].replace("City Hotel", "城市酒店", inplace=True) room_price_monthly["hotel"].replace("Resort Hotel", "度假酒店", inplace=True) room_price_monthly.head(15) plt.figure(figsize=(12, 8)) sns.lineplot(x="arrival_date_month", y="adr_pp", hue="hotel", data=room_price_monthly, hue_order=["城市酒店", "度假酒店"], ci="sd", size="hotel", sizes=(2.5, 2.5)) plt.title("不同月份人均居住价格/晚", fontsize=16) plt.xlabel("月份", fontsize=16) plt.ylabel("人均居住价格/晚", fontsize=16) # plt.savefig("F:/文章/不同月份人均居住价格每晚")
相关文章推荐
- Mac 解决 Font family [“sans-serif”] not found , Glyph xxx missing from current font 的问题
- matplotlib绘图不显示问题解决plt.show()
- Python之Matplotlib 解决绘图 X 轴值不按数组排序问题.
- 基本绘图示例,以及解决matplotlib中文乱码的问题
- Matplotlib is building the font cache using fc-list. This may take a moment解决办法
- 解决Windows系统下python利用matplotlib绘图时中文乱码的问题
- 【Python开发】matplotlib绘图不显示问题解决plt.show()
- 解决Python中Matplotlib绘图汉字不能正常显示问题
- Python使用matplotlib绘图无法显示中文问题的解决方法
- 详解Python Matplotlib解决绘图X轴值不按数组排序问题
- python 使用matplotlib绘图中文显示成框框解决办法
- Ubuntu下matplotlib绘图中文乱码问题的解决
- 解决 Python Matplotlib 绘图时不连续x轴自动补全的问题(xsticks)
- matplotlib 中子图subplot 绘图时标题重叠解决办法(备忘)
- 解决matplotlib绘图中显示中文乱码的问题
- 【Python开发】matplotlib绘图不显示问题解决plt.show()
- 完美解决Python下matplotlib绘图中文乱码问题
- matplotlib无法显示中文和符号及未完全显示绘图的解决办法
- 解决python中matplotlib绘图中文显示问题
- Matplotlib is building the font cache using fc-list. This may take a moment解决办法