Anaconda+5.0.0+JupyterLab+0.27.0+中matplotlib显示中文标签
来源:互联网 发布:程序设计用什么软件 编辑:程序博客网 时间:2024/05/16 09:55
Anaconda 5.0.0 JupyterLab 0.27.0 中 matplotlib 显示中文标签
安全的安装Anaconda3 5.0.0 Windows x86_64
http://blog.csdn.net/hu_zhenghui/article/details/78154684
Anaconda 5.0.0 JupyterLab 0.27.0 中 matplotlib 显示中文标签
使用 matplotlib 绘制数据图的时候可能会涉及到本地化显示,例如导入 locale 包
import locale
为了绘制数据图,导入 matplotlib.pyplot 包
import matplotlib.pyplot
本例中以日期为例,导入 datetime 包
import datetime
为了以本地格式显示日期,设置地区,此处并未具体制定地区,而是使用 locale.LC_ALL
,从返回值可以看到是简体中文
locale.setlocale(locale.LC_ALL, '')
'Chinese (Simplified)_China.936'
演示数据
data = range(-7,7)
演示数据的标签
label = [(datetime.datetime.now() + datetime.timedelta(days=i)).strftime('%A') for i in data]
创建一个数据图
figure1 = matplotlib.pyplot.figure(figsize=(10,10))
添加一个坐标轴
axes1 = figure1.add_subplot(1,1,1)
使用演示数据和演示标签绘制柱状图
axes1.bar(data, data, tick_label=label)
<Container object of 14 artists>
保存数据图
figure1.savefig('1.png')
可以看到标签都显示成了空白方块
为了正确显示中文,需要替换数据图绘制时所使用的字体
matplotlib.pyplot.rcParams['font.sans-serif']=['SimHei']
创建第二个数据图
figure2 = matplotlib.pyplot.figure(figsize=(10,10))
为第二个数据图添加坐标轴
axes2 = figure2.add_subplot(1,1,1)
使用演示数据和演示标签绘制柱状图
axes2.bar(data, data, tick_label=label)
<Container object of 14 artists>
保存数据图
figure2.savefig('2.png')
可以看到数据标签显示正常了,但是负数的数据前面又出现了空白方块。
为此需要设置坐标轴中不使用 unicode 显示-
减号
matplotlib.pyplot.rcParams['axes.unicode_minus']=False
创建第三个数据图
figure3 = matplotlib.pyplot.figure(figsize=(10,10))
为第三个数据图添加坐标轴
axes3 = figure3.add_subplot(1,1,1)
使用演示数据和演示标签绘制柱状图
axes3.bar(data, data, tick_label=label)
<Container object of 14 artists>
保存数据图
figure3.savefig('3.png')
可以看到数据标签和数据都正常了
阅读全文
0 0
- Anaconda+5.0.0+JupyterLab+0.27.0+中matplotlib显示中文标签
- Anaconda 5.0.0 JupyterLab 0.27.0 中使用 matplotlib basemap 绘制世界地图
- Anaconda 5.0.0 JupyterLab 0.27.0 中配置 plotly 支持
- Anaconda 5.0.0 JupyterLab 0.27.0 中配置多Python环境支持
- Anaconda 5.0.0 JupyterLab 0.27.0 中通过 SSH 访问远程 Linux 服务器
- 在matplotlib中显示中文
- python中matplotlib绘图中文显示问题
- python中matplotlib绘图中文显示问题
- python中matplotlib绘图中文显示问题
- ipython中matplotlib中文显示问题
- python中matplotlib绘图中文显示问题
- python中matplotlib绘图中文显示问题
- matplotlib-在图表中显示中文
- python中matplotlib画图中文不能显示
- python matplotlib中显示中文问题
- 基于 Anaconda3 5.0.0 JupyterLab 0.27.0 使用 ftplib 演示 IPv4 和 IPv6 上传文件和下载文件
- matplotlib显示中文问题
- matplotlib 中文显示
- 容器和底层数据结构
- 算法(3) 移动平均算法 moving average
- 区间修改,区间查询
- CV资料
- maven工程运行报错:软件包javax.crypto 不存在解决办法
- Anaconda+5.0.0+JupyterLab+0.27.0+中matplotlib显示中文标签
- 文本分类-特征选择方法
- JS常见算法
- 【技术贴收集】微信视频播放全屏问题
- 树状数组模板
- 【linux】复制文件部分内容到另外一个文件
- 矩阵最小二乘与Tikhonov正则化
- Python数据结构——序列、字典
- java 反射的原理