glyph 24230 missing from current font.解决-matplotlib绘图踩坑
问题描述
用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 inlineplt.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:/文章/不同月份人均居住价格每晚")
参考:
解决Python使用matplotlib绘图时出现的中文乱码问题 (by 逝不等琴生)
glyph 24230 missing from current font.解决-matplotlib绘图踩坑相关推荐
- Glyph 26426 missing from current font.解决matplotlib画图中文字体乱码问题
1. 问题复现 环境:Ipython 3.8 import matplotlib.pyplot as plt import pandas as pddata = pd.read_csv('/Users ...
- python出现中文乱码 RuntimeWarning: Glyph 24180 missing from current font.解决方法
文章目录 遇到的问题 解决方法 参考 解决方法:在画图前添加这样一句代码 plt.rcParams['font.sans-serif'] = ['SimHei'] 遇到的问题 环境:win10,编辑器 ...
- RuntimeWarning:Glyph 21435 missing from current font.
RuntimeWarning:Glyph 21435 missing from current font. 目录 RuntimeWarning:Glyph 21435 missing from cur ...
- 错误RuntimeWarning: Glyph xxxxx missing from current font的产生原因解析,检测当前字体是否包含某字符
RuntimeWarning: Glyph xxxx missing from current font是matplotlib的经典错误. 原因大家都清楚:字体不匹配,显示不了对应的字符. 现象就是: ...
- matplotlib解决中文乱码问题,或者RuntimeWarning: Glyph 20154 missing from current font.
matplotlib解决乱码问题 如图:为图表添加名称时报措,如何处理. 添加代码: from pylab import mplmpl.rcParams['font.sans-serif'] =[&q ...
- RuntimeWarning: Glyph 30452 missing from current font. matplotlib画图无法显示中文
matplotlib画图无法显示中文 RuntimeWarning: Glyph 30452 missing from current font. plt画图的title显示的中文是方括号 错误图: ...
- 出现RuntimeWarning: Glyph 39057 missing from current font.的解决办法:
出现RuntimeWarning: Glyph 39057 missing from current font.的解决办法: 在程序开头添加如下程序: import matplotlib as mpl ...
- Glyph 8722 missing from current font, matplotlib画图
背景: win10, anaconda 4.8.3, python3.8.3 matplotlib画图, 小程序运行时,图像中坐标轴"负号"显示不全,(我这里)表现为"方 ...
- Matplotlib绘图显示缺少中文字体-RuntimeWarning: Glyph 8722 missing from current font.
pyplot 并不默认支持中文显示,也没有自带中文字体,因此需要自行下载所需字体,并修改 rcParams 参数来显示中文.下面以 SimHei (黑体)字体为例进行说明. 说明:系统环境为 Linu ...
最新文章
- 如何写网站的robots.txt和meta name robots的配置
- #QCon# Devops
- [原创]Zynq SDIO WIFI SotfAP调试
- sqlserver获取当前时间_c#获取并显示当前日期时间
- 【面向对象】包可见性和友元可见性
- 【gateway系列】一步步带你学习gateway路由规则实践
- Win10设置定时关机命令简单介绍
- 产品经理(PM)的工作流程
- 一个vscode自动attach进程的插件开发实例
- Deity is on the struggling road too!
- 快速部署阿里云WebIDE(DevStudio)并参与开源项目开发
- 如何在PPT中用文本框制作海报?这个方法很简单,不信来看
- vue导致页面白屏几种情况
- 我做出一个决定!(2-3nian后时间来证明对错!)
- Nesterov加速算法
- 昆山市地方税务局异地复制及备份系统询价采购招标公告
- 【区块链与密码学】第6-7讲:SM9数字签名算法
- RK3399的Android系统驱动UVC摄像头
- NXP S32K3 用PIT的RTI定时器来唤醒MCU
- Linux应用随笔(八)各类软件工具整理
热门文章
- C语言生成随机数代码
- BGP选路原则和选路控制
- 微信小程序小案例——简单数据增删改查模拟
- 力扣312场周赛:按身高排序
- Premiere颜色插件 Synthetic-Aperture.Color.Finesse.Pl.v3.1.0.CE (x64) PR/AE版本
- vue身份证号脱敏显示
- opencv-python灰度直方图详解
- php工程师历程,从PHP学习历程分析PHP工程师前景
- ubuntu16.04+gtx1060+cuda8.0+caffe安装、测试经历
- ARM CMSIS DAP源码分析