LovelyPlots库 可以很好地格式化科学论文、论文和演示文稿的可视化图形,同时使它们在 Adobe Illustrator 中完全可编辑。
此外,.svg 导出选项允许图形自动调整其字体以适应您文档的字体。 例如,导入到 .tex 文件中的 .svg 图形将自动生成为您的 .tex 文件中使用的文本字体。
安装
pip3 install LovelyPlots
样例
代码
import matplotlib.pyplot as plt
import numpy as np
def MB_speed(v, m, T):
"""Maxwell-Boltzmann speed distribution for speeds"""
kB = 1.38e-23
return (
(m / (2 * np.pi * kB * T)) ** 1.5 * 4 * np.pi * v**2 * np.exp(-m * v**2 / (2 * kB * T))
)
def plot_dist(
temperatures,
v,
mass=85 * 1.66e-27,
pparam={"xlabel": "Speed", "ylabel": "Speed distribution"},
save_name="",
):
fig, ax = plt.subplots()
for T in temperatures:
fv = MB_speed(v, mass, T)
ax.plot(v, fv, label=f"T={T}K")
ax.legend()
ax.set(**pparam)
fig.savefig(save_name)
v = np.arange(0, 800, 10)
temperatures = [i for i in range(100, 500, 75)]
styles = [
[
"ipynb",
"use_mathtext",
],
[
"ipynb",
"use_mathtext",
"colors5-light",
],
[
"ipynb",
"use_mathtext",
"colors10-ls",
],
[
"ipynb",
"use_mathtext",
"colors10-markers",
],
["classic"],
["ipynb"],
]
names = [
"out/ipynb+use_mathtext.png",
"out/ipynb+use_mathtext+colors5-light.png",
"out/ipynb+use_mathtext+colors10-ls.png",
"out/ipynb+use_mathtext+colors10-markers.png",
"out/classicmpl.png",
"out/ipynb.png",
]
for style, name in zip(styles, names):
with plt.style.context(style):
plot_dist(temperatures, v, save_name=name)