今天给大家介绍一个好用的Python绘图拓展工具-TUEplots,可以帮助使用者轻松将绘图结果调整成符合出版级别的可视化结果。
TUEplots 是 matplotlib 的一个轻量级扩展绘图工具,可将图形尺寸调整为更适合科学出版物的格式。它能生成与 matplotlib的rcParams兼容的配置,并为多种出版物格式提供字体、图形大小、字号、配色方案等。除此之外,TUEplots还捆绑了一些期刊的预设图形样式,如下:
可使用pip对TUEplots包进行安装。如下:
pip install tueplots
安装最新版本可使用如下语句:
pip install git+https://github.com/pnkraemer/tueplots.git
import matplotlib.pyplot as plt
plt.rcParams.update(axes.color(base="red"))
fig, ax = plt.subplots()
ax.plot([1.0, 2.0], [3.0, 4.0], label="ABC")
ax.set_xlabel("xlabel")
ax.set_ylabel("ylabel")
ax.set_title("title")
plt.grid()
plt.show()
子图样式绘图示例
with plt.rc_context({**bundles.icml2022(), **axes.lines()}):
fig, ax = plt.subplots()
ax.plot([1.0, 2.0], [3.0, 4.0], label="p(x)")
ax.set_title("Title")
ax.set_xlabel("xlabel $\int f(x) dx$")
ax.set_ylabel("ylabel $x \sim \mathcal{N}(x)$")
plt.grid()
plt.legend()
plt.show()
bundles.icml2022()图形样式
import matplotlib.pyplot as plt
import numpy as np
from tueplots import cycler
from tueplots.constants import markers
from tueplots.constants.color import palettes
# Increase the resolution of all the plots below
plt.rcParams.update({"figure.dpi": 150})
x = np.linspace(0, np.pi, 20)
offsets = np.linspace(0, 2 * np.pi, 8, endpoint=False)
yy = [np.sin(x + phi) for phi in offsets]
Matplotlib默认分类颜色色系样式如下:
Matplotlib默认分类颜色色系
palettes.tue_plot
palettes.muted
palettes.high_contrast
palettes.pn
还可以添加散点样式类型,如下:
import matplotlib.pyplot as plt
import numpy as np
from tueplots import cycler, markers
from tueplots.constants import markers as marker_constants
from tueplots.constants.color import palettes
# Increase the resolution of all the plots below
plt.rcParams.update({"figure.dpi": 150})
x = np.linspace(0, np.pi, 25)
offsets = np.linspace(0, 2 * np.pi, 7, endpoint=False)
yy = [np.sin(x + phi) for phi in offsets]
#修改样式
plt.rcParams.update(
cycler.cycler(marker=marker_constants.o_sized[:5], color=palettes.pn[:5])
)
fig, ax = plt.subplots()
for y in yy:
ax.plot(x, y, linewidth=1)
plt.show()
点样式01
plt.rcParams.update(markers.with_edge(edgecolor="green", edgewidth=1.0))
fig, ax = plt.subplots()
for y in yy:
ax.plot(x, y, linewidth=1)
plt.show()
点样式02
其他如画布(FIgure)大小、选择正确的字体及调整字体大小等操作的介绍,读者可阅读,tueplots官网[1]
今天介绍的tueplots可视化工具,可以让使用者快速提供一个绘制出版级别可视化图形,节省后期图形修改的时间,大大节省时间,特别是针对某几个期刊要求的指定配图样式,喜欢的同学可以安装使用一下~~
[1]
tueplots官网: https://tueplots.readthedocs.io/en/latest/index.html。