POT工具的标志

在这个例子中,我们绘制了POT工具箱的标志。

这个徽标是完全使用Python制作的,并使用matplotlib生成了POT中的EMD求解器的解。

# Author: Remi Flamary <remi.flamary@polytechnique.edu>
#
# License: MIT License

# sphinx_gallery_thumbnail_number = 1
import numpy as np
import matplotlib.pyplot as pl
import ot

绘制logo(清晰背景)

# Solve OT problem between the points
M = ot.dist(x1, x2, metric="euclidean")
T = ot.emd([], [], M)

pl.figure(1, (3.5, 1.1))
pl.clf()
# plot the OT plan
for i in range(M.shape[0]):
    for j in range(M.shape[1]):
        if T[i, j] > 1e-8:
            pl.plot(
                [x1[i, 0], x2[j, 0]],
                [x1[i, 1], x2[j, 1]],
                color="k",
                alpha=0.6,
                linewidth=3,
                zorder=1,
            )
# plot the samples
pl.plot(x1[:, 0], x1[:, 1], "o", markerfacecolor="C3", markeredgecolor="k")
pl.plot(x2[:, 0], x2[:, 1], "o", markerfacecolor="b", markeredgecolor="k")


pl.axis("equal")
pl.axis("off")

# Save logo file
# pl.savefig('logo.svg', dpi=150, transparent=True, bbox_inches='tight')
# pl.savefig('logo.png', dpi=150, transparent=True, bbox_inches='tight')
plot logo
(np.float64(-0.43), np.float64(9.03), np.float64(0.375), np.float64(3.125))

绘制logo(黑色背景)

pl.figure(2, (3.5, 1.1), facecolor="darkgray")
pl.clf()
# plot the OT plan
for i in range(M.shape[0]):
    for j in range(M.shape[1]):
        if T[i, j] > 1e-8:
            pl.plot(
                [x1[i, 0], x2[j, 0]],
                [x1[i, 1], x2[j, 1]],
                color="w",
                alpha=0.8,
                linewidth=3,
                zorder=1,
            )
# plot the samples
pl.plot(x1[:, 0], x1[:, 1], "o", markerfacecolor="w", markeredgecolor="w")
pl.plot(x2[:, 0], x2[:, 1], "o", markerfacecolor="w", markeredgecolor="w")

pl.axis("equal")
pl.axis("off")

# Save logo file
# pl.savefig('logo_dark.svg', dpi=150, transparent=True, bbox_inches='tight')
# pl.savefig('logo_dark.png', dpi=150, transparent=True, bbox_inches='tight')
plot logo
(np.float64(-0.43), np.float64(9.03), np.float64(0.375), np.float64(3.125))

脚本的总运行时间: (0分钟 0.087秒)

由 Sphinx-Gallery 生成的画廊