matplotlib - 将带有 LaTeX 字体的 Matplotlib 图保存为 eps
问题描述
我正在尝试使用 matplotlib 和 LaTeX 字体在 Jupyter-lab 中制作出版质量。我按照此处的说明创建了一个简单的文档: https ://matplotlib.org/stable/tutorials/text/usetex.html
图表是用漂亮的字体创建的;但是,保存的 eps 文件是空白的。相同的图形可以成功保存为 png,但即使使用dpi=2400
选项导入到 LaTeX 时它看起来也很模糊。导入 LaTeX 文件时,没有 LaTeX 字体的 Eps 文件像剃刀一样锋利。
建议?解决方法?
谢谢,拉多万
PS。我发现的一种解决方法是使用 gnuplot 和cairolatex
终端...生成的 *.tex 文件可以编译并Pdflatex
获得出色的结果。但那是一个不同的故事:-)。
解决方案
我又试了一次。最后,它确实奏效了!这是代码:
import numpy as np
import matplotlib.pyplot as plt
## reset defaults
plt.rcdefaults()
## Set up LaTeX fonts
plt.rcParams.update({
"text.usetex": True,
"font.family": "serif",
"font.serif": ["Computer Modern Roman"],
"font.size": 14,
})
## Data for plotting
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
fig, ax = plt.subplots(figsize=(4.5,3))
ax.plot(t, s, linewidth=3)
ax.set(xlabel=r'time $\tau_p$ [$\mu$s]', ylabel=r'voltage (mV)')
ax.set(title=r'$ E = m c^2 $')
fig.savefig("test600.png", format="png", dpi=600, bbox_inches="tight")
fig.savefig("test1200t.eps", format="eps", dpi=1200, bbox_inches="tight", transparent=True)
fig.savefig("test1200t.pdf", format="pdf", dpi=1200, bbox_inches="tight", transparent=True)
plt.show()
我不确定之前出了什么问题。这次我做了不同的字体声明。
干杯,拉多万
推荐阅读
- excel - Excel:某些行内的动态范围+数据验证更新
- caching - AsyncTaskLoader:deliverResult,当AsyncTaskLoader中的变量(用于缓存)为null时(表示调用)
- javascript - 无法使用 Functions:Shell 将新文档添加到 Firestore 中的集合
- python - 一旦由monkeypatch为单例类设置,就无法覆盖函数的初始化值
- jsf - 用于布尔值的 JSF 或 PrimeFaces 组件/如何将布尔值与 p:triStateCheckbox 一起使用
- concurrentdictionary - 将项目存储在 ConcurrentDictionary 中,并将项目的键作为它在 C# 中的字典中出现的次数
- macos - 如何在 macos 上安装 perl 模块?
- r - R 等价于 Stata 的 bysort xy (z):
- sql - 使用第一个查询获取每个线程的第一个值并使用该值执行第二个查询
- mysql - 不同属性的连接计数