matplotlib - 如何在 jupyter notebook 中使用非衬线字体制作 matplotlib 绘图?
问题描述
我想在非衬线字体的 jupyter 笔记本中使用乳胶绘图。
我安装了一些软件包:
sudo apt install font-manager texlive-latex-base texlive-latex-extra texlive-math-extra dvipng
我清除了 matplotlib 缓存:
rm ~/.cache/matplotlib -rf
我正在使用这段代码:
%pylab inline
rcParams['text.usetex'] = True
rcParams['text.latex.unicode'] = True
rcParams['text.latex.preamble'] = [r'\usepackage{amsmath}']
plot(range(10))
title('Test')
xlabel('Test')
虽然情节有衬线刻度标签:
解决方案
使用该功能激活乳胶后rc
,使用以下乳胶前导似乎是获得所需结果所必需的。这有效,但我不知道为什么。我猜%pylab inline
有魔法吗?你甚至不必告诉matplotlib
使用这样的无衬线字体。\mathrm
使标题中的公式变为非斜体。
%pylab inline
figure(dpi=100)
rc('text', usetex=True)
rcParams['text.latex.preamble'] = [r'\usepackage[cm]{sfmath}']
plot(np.arange(10)/10)
xlabel(r'Time $i_{k} [s]$', size=12)
title('$\mathrm{\sum_{i} T_i}$')
推荐阅读
- java - Why is printstacktrace() of exception method does not print to console when ever called?
- javascript - 这两种在 Javascript 对象中编写方法的方法有什么区别?
- java - 如何将@Inject 注入可运行对象?
- c# - 除了 pdf 中的 js 之外,有没有办法在 Acrobat/IE 中自动标记 pdf 字段?
- android - Android Studio - 视频音量低
- android - 暴露在 Android 库中定义的 Dagger 组件
- excel - 如何计算阴影且大于某个值的单元格
- ios - Swift 分配一个浮点变量
- node.js - 未捕获的类型错误:gax.GoogleProtoFilesRoot 不是构造函数
- xcode - 使用镜像容器进行开发