前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >TUEplots,一天100张论文配图,导师惊了···

TUEplots,一天100张论文配图,导师惊了···

作者头像
DataCharm
发布2023-10-07 11:18:14
2860
发布2023-10-07 11:18:14
举报
文章被收录于专栏:数据 学术 商业 新闻

今天给大家介绍一个好用的Python绘图拓展工具-TUEplots,可以帮助使用者轻松将绘图结果调整成符合出版级别的可视化结果。

TUEplots 是 matplotlib 的一个轻量级扩展绘图工具,可将图形尺寸调整为更适合科学出版物的格式。它能生成与 matplotlib的rcParams兼容的配置,并为多种出版物格式提供字体、图形大小、字号、配色方案等。除此之外,TUEplots还捆绑了一些期刊的预设图形样式,如下:

  • Conference on Neural Information Processing Systems (NeurIPS)
  • International Conference on Artificial Intelligence and Statistics (AISTATS)
  • International Conference on Learning Representations (ICLR)
  • International Conference on Machine Learning (ICML)
  • Conference on Uncertainty in Artificial Intelligence (UAI)
  • Journal of Machine Learning Research (JMLR)

安装

可使用pip对TUEplots包进行安装。如下:

代码语言:javascript
复制
pip install tueplots

安装最新版本可使用如下语句:

代码语言:javascript
复制
pip install git+https://github.com/pnkraemer/tueplots.git

绘图案例

  • 子图样式 可通过如下语句对matplotlib子图样式进行修改:
代码语言:javascript
复制
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()

子图样式绘图示例

  • 使用内置捆绑样式
代码语言:javascript
复制
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()图形样式

  • 颜色色系样式 通过tueplots包中的cycler、palettes等属性,可以轻松修改Matplotlib默认的色系:
代码语言:javascript
复制
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

还可以添加散点样式类型,如下:

  • 修改散点样式 通过引入tueplots包中的markers类中的各个属性,可以一键式修改绘图结果中的数据点样式及颜色,详细如下:
代码语言:javascript
复制
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

代码语言:javascript
复制
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。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-10-06 19:02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 DataCharm 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 安装
  • 绘图案例
  • 总结
    • 参考资料
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档