{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Logo of the POT toolbox\n\n

Note

Example added in release: 0.8.2.

\n\nIn this example we plot the logo of the POT toolbox.\n\nThis logo is that it is done 100% in Python and generated using\nmatplotlib and plotting the solution of the EMD solver from POT.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Author: Remi Flamary \n#\n# License: MIT License\n\n# sphinx_gallery_thumbnail_number = 1" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nimport matplotlib.pyplot as pl\nimport ot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Data for logo\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Letter P\np1 = np.array(\n [\n [0, 6.0],\n [0, 5],\n [0, 4],\n [0, 3],\n [0, 2],\n [0, 1],\n ]\n)\np2 = np.array(\n [\n [1.5, 6],\n [2, 4],\n [2, 5],\n [1.5, 3],\n [0.5, 2],\n [0.5, 1],\n ]\n)\n\n# Letter O\no1 = np.array(\n [\n [0, 6.0],\n [-1, 5],\n [-1.5, 4],\n [-1.5, 3],\n [-1, 2],\n [0, 1],\n ]\n)\no2 = np.array(\n [\n [1, 6.0],\n [2, 5],\n [2.5, 4],\n [2.5, 3],\n [2, 2],\n [1, 1],\n ]\n)\n\n# Scaling and translation for letter O\no1[:, 0] += 6.4\no2[:, 0] += 6.4\no1[:, 0] *= 0.6\no2[:, 0] *= 0.6\n\n# Letter T\nt1 = np.array(\n [\n [-1, 6.0],\n [-1, 5],\n [0, 4],\n [0, 3],\n [0, 2],\n [0, 1],\n ]\n)\nt2 = np.array(\n [\n [1.5, 6.0],\n [1.5, 5],\n [0.5, 4],\n [0.5, 3],\n [0.5, 2],\n [0.5, 1],\n ]\n)\n\n# Translating the T\nt1[:, 0] += 7.1\nt2[:, 0] += 7.1\n\n# Concatenate all letters\nx1 = np.concatenate((p1, o1, t1), axis=0)\nx2 = np.concatenate((p2, o2, t2), axis=0)\n\n# Horizontal and vertical scaling\nsx = 1.0\nsy = 0.5\nx1[:, 0] *= sx\nx1[:, 1] *= sy\nx2[:, 0] *= sx\nx2[:, 1] *= sy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot the logo (clear background)\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Solve OT problem between the points\nM = ot.dist(x1, x2, metric=\"euclidean\")\nT = ot.emd([], [], M)\n\npl.figure(1, (3.5, 1.1))\npl.clf()\n# plot the OT plan\nfor i in range(M.shape[0]):\n for j in range(M.shape[1]):\n if T[i, j] > 1e-8:\n pl.plot(\n [x1[i, 0], x2[j, 0]],\n [x1[i, 1], x2[j, 1]],\n color=\"k\",\n alpha=0.6,\n linewidth=3,\n zorder=1,\n )\n# plot the samples\npl.plot(x1[:, 0], x1[:, 1], \"o\", markerfacecolor=\"C3\", markeredgecolor=\"k\")\npl.plot(x2[:, 0], x2[:, 1], \"o\", markerfacecolor=\"b\", markeredgecolor=\"k\")\n\n\npl.axis(\"equal\")\npl.axis(\"off\")\n\n# Save logo file\n# pl.savefig('logo.svg', dpi=150, transparent=True, bbox_inches='tight')\n# pl.savefig('logo.png', dpi=150, transparent=True, bbox_inches='tight')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot the logo (dark background)\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "pl.figure(2, (3.5, 1.1), facecolor=\"darkgray\")\npl.clf()\n# plot the OT plan\nfor i in range(M.shape[0]):\n for j in range(M.shape[1]):\n if T[i, j] > 1e-8:\n pl.plot(\n [x1[i, 0], x2[j, 0]],\n [x1[i, 1], x2[j, 1]],\n color=\"w\",\n alpha=0.8,\n linewidth=3,\n zorder=1,\n )\n# plot the samples\npl.plot(x1[:, 0], x1[:, 1], \"o\", markerfacecolor=\"w\", markeredgecolor=\"w\")\npl.plot(x2[:, 0], x2[:, 1], \"o\", markerfacecolor=\"w\", markeredgecolor=\"w\")\n\npl.axis(\"equal\")\npl.axis(\"off\")\n\n# Save logo file\n# pl.savefig('logo_dark.svg', dpi=150, transparent=True, bbox_inches='tight')\n# pl.savefig('logo_dark.png', dpi=150, transparent=True, bbox_inches='tight')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.18" } }, "nbformat": 4, "nbformat_minor": 0 }