Note
Click here to download the full example code
02. Plot favicons
This example lists all the libraries installed in the environment using pip, gets their site url, downloads the icon and displays it in the example.
Note
The command cut
is not available in windows! Thus, the
code will not run in te standard Windows Command Prompt. However,
it might be available on Cygwin o Git for windows.
14 # Libraries
15 import favicon
16 import subprocess as sp
17
18
19 class IconHTML:
20 """Class to display html in sphinx-gallery."""
21 TMP0 = '<img src={url} style="{s}", width={w} height={h}>'
22 TMP1 = '<div>'+TMP0+' <span>{name}</span></div>'
23
24 """Class to display icons on sphinx-gallery."""
25 def __init__(self, d, width=25, height=25, verbose=0):
26 self.d = d
27 self.width = width
28 self.height = height
29 self.style = "display: inline; vertical-align:middle;"
30 self.verbose = verbose
31
32 def _repr_html_short_(self):
33 return ' '.join([self.TMP0.format(url=v,
34 w=self.width, h=self.height, s=self.style)
35 for k,v in self.d.items()])
36
37 def _repr_html_long_(self):
38 return ' '.join([self.TMP1.format(url=v,
39 w=self.width, h=self.height, s=self.style, name=k.lower())
40 for k, v in self.d.items()])
41
42 def _repr_html_(self):
43 if self.verbose == 0:
44 return self._repr_html_short_()
45 return self._repr_html_long_()
46
47
48 # List of libraries for which the icon (if found)
49 # should be included in the output.
50 INCLUDE = [
51 'pandas',
52 'Flask',
53 'imblearn',
54 'numba',
55 'numpy',
56 'plotly',
57 'PyYAML',
58 'scipy',
59 'seaborn',
60 'statsmodels',
61 'alabaster',
62 'attrs',
63 'Babel',
64 'bokeh',
65 'joblib',
66 'nltk',
67 'notebook',
68 'torch',
69 'matplotlib',
70 'pillow',
71 'pygments',
72 'pytest',
73 'tqdm',
74 'urllib3',
75 'future'
76 ]
77
78 # Define command to list packages and urls
79 COMMAND = "pip list --format=freeze | cut -d= -f1 | xargs pip show | "
80 COMMAND+= "awk '/^Name/{printf $2} /^Home-page/{print \": \"$2}'"
81
82 # List of package name and url.
83 output = sp.getoutput(COMMAND)
84
85 # Show
86 print("\nCommand output:")
87 print(output)
88
89 # Create dictionary
90 d = {}
91 for line in output.split("\n")[2:]:
92 # Find name and url
93 name, url = line.split(': ')
94 if not url.startswith('https:'):
95 continue
96 if name not in INCLUDE:
97 continue
98 # Store name and url
99 icons = favicon.get(url)
100 for i, ico in enumerate(icons):
101 d['%s-%s' % (name, i)] = ico.url
Out:
Command output:
absl-py: https://github.com/abseil/abseil-py
aiohttp: https://github.com/aio-libs/aiohttp
aiosignal: https://github.com/aio-libs/aiosignal
alabaster: https://alabaster.readthedocs.io/
anyio:
appnope: http://github.com/minrk/appnope
argon2-cffi:
argon2-cffi-bindings: https://github.com/hynek/argon2-cffi-bindings
arrow: https://arrow.readthedocs.io
asttokens: https://github.com/gristlabs/asttokens
astunparse: https://github.com/simonpercivall/astunparse
async-timeout: https://github.com/aio-libs/async-timeout
attrs:
babel: https://babel.pocoo.org/
backcall: https://github.com/takluyver/backcall
beautifulsoup4: https://www.crummy.com/software/BeautifulSoup/bs4/
bleach: https://github.com/mozilla/bleach
bokeh: https://github.com/bokeh/bokeh
Brotli: https://github.com/google/brotli
bs4: https://pypi.python.org/pypi/beautifulsoup4
cachetools: https://github.com/tkem/cachetools/
certifi: https://github.com/certifi/python-certifi
cffi: http://cffi.readthedocs.org
charset-normalizer: https://github.com/Ousret/charset_normalizer
click: https://palletsprojects.com/p/click/
cloudpickle: https://github.com/cloudpipe/cloudpickle
comm: https://github.com/ipython/comm
contourpy:
cryptography: https://github.com/pyca/cryptography
cycler: https://github.com/matplotlib/cycler
dacite: https://github.com/konradhalas/dacite
dash: https://plotly.com/dash
dash-core-components: UNKNOWN
dash-html-components: https://github.com/plotly/dash-html-components
dash-table: UNKNOWN
dask: https://github.com/dask/dask/
dataprep: https://github.com/sfu-db/dataprep
deap: https://www.github.com/deap
debugpy: https://aka.ms/debugpy
decorator: https://github.com/micheles/decorator
defusedxml: https://github.com/tiran/defusedxml
docutils: http://docutils.sourceforge.net/
et-xmlfile: https://foss.heptapod.net/openpyxl/et_xmlfile
executing: https://github.com/alexmojaki/executing
factory-boy: https://github.com/FactoryBoy/factory_boy
Faker: https://github.com/joke2k/faker
fastjsonschema: https://github.com/horejsek/python-fastjsonschema
favicon: https://github.com/scottwernervt/favicon
filelock: https://github.com/tox-dev/py-filelock
Flask: https://palletsprojects.com/p/flask
Flask-Compress: https://github.com/colour-science/flask-compress
Flask-Cors: https://github.com/corydolphin/flask-cors
flatbuffers: https://google.github.io/flatbuffers/
fonttools: http://github.com/fonttools/fonttools
fqdn: https://github.com/ypcrts/fqdn
frozenlist: https://github.com/aio-libs/frozenlist
fsspec: http://github.com/fsspec/filesystem_spec
gast: https://github.com/serge-sans-paille/gast/
google-auth: https://github.com/googleapis/google-auth-library-python
google-auth-oauthlib: https://github.com/GoogleCloudPlatform/google-auth-library-python-oauthlib
google-pasta: https://github.com/google/pasta
graphviz: https://github.com/xflr6/graphviz
grpcio: https://grpc.io
h5py: https://www.h5py.org/
hiplot: https://github.com/facebookresearch/hiplot
html2image: https://github.com/vgalin/html2image
htmlmin: https://htmlmin.readthedocs.io/en/latest/
idna:
ImageHash: https://github.com/JohannesBuchner/imagehash
imagesize: https://github.com/shibukawa/imagesize_py
importlib-metadata: https://github.com/python/importlib_metadata
ipykernel: https://ipython.org
ipython: https://ipython.org
ipython-genutils: http://ipython.org
ipywidgets: http://ipython.org
isoduration: https://github.com/bolsote/isoduration
itsdangerous: https://palletsprojects.com/p/itsdangerous/
jax: https://github.com/google/jax
jedi: https://github.com/davidhalter/jedi
Jinja2:
joblib: https://joblib.readthedocs.io
jsonpath-ng: https://github.com/h2non/jsonpath-ng
jsonpointer: https://github.com/stefankoegl/python-json-pointer
jsonschema: https://github.com/python-jsonschema/jsonschema
jupyter_client: https://jupyter.org
jupyter_core: https://jupyter.org
jupyter-events: http://jupyter.org
jupyter_server: https://jupyter-server.readthedocs.io
jupyter_server_terminals: https://jupyter.org
jupyterlab-pygments: https://github.com/jupyterlab/jupyterlab_pygments
jupyterlab-widgets: https://github.com/jupyter-widgets/ipywidgets
kaleido: UNKNOWN
keras: https://keras.io/
kiwisolver: https://github.com/nucleic/kiwi
libclang: https://github.com/sighingnow/libclang
llvmlite: http://llvmlite.readthedocs.io
locket: http://github.com/mwilliamson/locket.py
Markdown: https://Python-Markdown.github.io/
MarkupSafe: https://palletsprojects.com/p/markupsafe/
matplotlib: https://matplotlib.org
matplotlib-inline: https://github.com/ipython/matplotlib-inline
Metaphone: https://github.com/oubiwann/metaphone
mistune: https://github.com/lepture/mistune
ml-dtypes: https://github.com/jax-ml/ml_dtypes
mpmath: http://mpmath.org/
multidict: https://github.com/aio-libs/multidict
multimethod: https://github.com/coady/multimethod
nbclassic: https://github.com/jupyter/nbclassic
nbclient: https://jupyter.org
nbconvert: https://jupyter.org
nbformat: https://jupyter.org
nest-asyncio: https://github.com/erdewit/nest_asyncio
networkx: https://networkx.org/
nltk: https://www.nltk.org/
notebook: http://jupyter.org
notebook_shim:
numba: https://numba.pydata.org
numpy: https://www.numpy.org
oauthlib: https://github.com/oauthlib/oauthlib
openpyxl: https://openpyxl.readthedocs.io
opt-einsum: https://github.com/dgasmith/opt_einsum
overrides: https://github.com/mkorpela/overrides
packaging:
pandas: https://pandas.pydata.org
pandas-profiling: https://github.com/ydataai/pandas-profiling
pandocfilters: http://github.com/jgm/pandocfilters
parso: https://github.com/davidhalter/parso
partd: http://github.com/dask/partd/
patsy: https://github.com/pydata/patsy
pdfminer.six: https://github.com/pdfminer/pdfminer.six
pdfplumber: https://github.com/jsvine/pdfplumber
pexpect: https://pexpect.readthedocs.io/
phik: http://phik.rtfd.io
pickleshare: https://github.com/pickleshare/pickleshare
Pillow: https://python-pillow.org
pip: https://pip.pypa.io/
platformdirs: https://github.com/platformdirs/platformdirs
plotly: https://plotly.com/python/
ply: http://www.dabeaz.com/ply/
prometheus-client: https://github.com/prometheus/client_python
prompt-toolkit: https://github.com/prompt-toolkit/python-prompt-toolkit
protobuf: https://developers.google.com/protocol-buffers/
psutil: https://github.com/giampaolo/psutil
ptyprocess: https://github.com/pexpect/ptyprocess
pure-eval: http://github.com/alexmojaki/pure_eval
pyamr: https://bahp.github.io/pyAMR/
pyasn1: https://github.com/etingof/pyasn1
pyasn1-modules: https://github.com/etingof/pyasn1-modules
pybaobabdt: https://gitlab.tue.nl/20040367/pybaobab
pycparser: https://github.com/eliben/pycparser
pydantic: https://github.com/pydantic/pydantic
pydot: https://github.com/pydot/pydot
Pygments: https://pygments.org
pyparsing: https://github.com/pyparsing/pyparsing/
pypdfium2: https://github.com/pypdfium2-team/pypdfium2
pyrsistent: https://github.com/tobgu/pyrsistent/
python-crfsuite: https://github.com/scrapinghub/python-crfsuite
python-dateutil: https://github.com/dateutil/dateutil
python-json-logger: http://github.com/madzak/python-json-logger
python-stdnum: https://arthurdejong.org/python-stdnum/
pytz: http://pythonhosted.org/pytz
PyWavelets: https://github.com/PyWavelets/pywt
PyYAML: https://pyyaml.org/
pyzmq: https://pyzmq.readthedocs.org
rapidfuzz: https://github.com/maxbachmann/RapidFuzz
regex: https://github.com/mrabarnett/mrab-regex
requests: https://requests.readthedocs.io
requests-oauthlib: https://github.com/requests/requests-oauthlib
rfc3339-validator: https://github.com/naimetti/rfc3339-validator
rfc3986-validator: https://github.com/naimetti/rfc3986-validator
rsa: https://stuvel.eu/rsa
scikit-learn: http://scikit-learn.org
scipy: https://scipy.org/
seaborn:
segment-anything:
Send2Trash: https://github.com/arsenetar/send2trash
setuptools: https://github.com/pypa/setuptools
shap: http://github.com/slundberg/shap
six: https://github.com/benjaminp/six
sklearn:
slicer: https://github.com/interpretml/slicer
sniffio: https://github.com/python-trio/sniffio
snowballstemmer: https://github.com/snowballstem/snowball
soupsieve: https://github.com/facelessuser/soupsieve
Sphinx: https://www.sphinx-doc.org/
sphinx-gallery: https://sphinx-gallery.github.io
sphinx-rtd-theme: https://github.com/readthedocs/sphinx_rtd_theme
sphinxcontrib-applehelp: https://www.sphinx-doc.org/
sphinxcontrib-devhelp: https://www.sphinx-doc.org/
sphinxcontrib-htmlhelp: https://www.sphinx-doc.org/
sphinxcontrib-jquery:
sphinxcontrib-jsmath: http://sphinx-doc.org/
sphinxcontrib-qthelp: https://www.sphinx-doc.org/
sphinxcontrib-serializinghtml: https://www.sphinx-doc.org/
SQLAlchemy: http://www.sqlalchemy.org
stack-data: http://github.com/alexmojaki/stack_data
statsmodels: https://www.statsmodels.org/
stopit: http://pypi.python.org/pypi/stopit
sympy: https://sympy.org
tableone: https://github.com/tompollard/tableone
tabulate: https://github.com/astanin/python-tabulate
tangled-up-in-unicode: https://github.com/dylan-profiler/tangled-up-in-unicode
tenacity: https://github.com/jd/tenacity
tensorboard: https://github.com/tensorflow/tensorboard
tensorboard-data-server: https://github.com/tensorflow/tensorboard/tree/master/tensorboard/data/server
tensorboard-plugin-wit: https://whatif-tool.dev
tensorflow: https://www.tensorflow.org/
tensorflow-estimator: https://www.tensorflow.org/
tensorflow-io-gcs-filesystem: https://github.com/tensorflow/io
termcolor: https://github.com/termcolor/termcolor
terminado: https://github.com/jupyter/terminado
threadpoolctl: https://github.com/joblib/threadpoolctl
tinycss2: https://www.courtbouillon.org/tinycss2
tomli: https://github.com/hukkin/tomli
toolz: https://github.com/pytoolz/toolz/
torch: https://pytorch.org/
torchvision: https://github.com/pytorch/vision
tornado: http://www.tornadoweb.org/
TPOT: https://github.com/EpistasisLab/tpot
tqdm: https://tqdm.github.io
traitlets: https://github.com/ipython/traitlets
typeguard: UNKNOWN
typing: https://docs.python.org/3/library/typing.html
typing_extensions:
tzdata: https://github.com/python/tzdata
update-checker: https://github.com/bboe/update_checker
uri-template: https://github.com/plinss/uri_template/
urllib3: https://urllib3.readthedocs.io/
varname: https://github.com/pwwang/python-varname
visions: https://github.com/dylan-profiler/visions
wcwidth: https://github.com/jquast/wcwidth
webcolors: https://github.com/ubernostrum/webcolors
webencodings: https://github.com/SimonSapin/python-webencodings
websocket-client: https://github.com/websocket-client/websocket-client.git
Werkzeug: https://palletsprojects.com/p/werkzeug/
wheel:
widgetsnbextension: http://ipython.org
wordcloud: https://github.com/amueller/word_cloud
wrapt: https://github.com/GrahamDumpleton/wrapt
xgboost: https://github.com/dmlc/xgboost
yarl: https://github.com/aio-libs/yarl/
ydata-profiling: https://github.com/ydataai/ydata-profiling
zipp: https://github.com/jaraco/zipp
106 aux = IconHTML(d)
107 aux
111 aux = IconHTML(d, verbose=1)
112 aux
117 # Create dictionary
118 d = {}
119 for line in output.split("\n")[2:]:
120 # Find name and url
121 name, url = line.split(': ')
122 if not url.startswith('https:'):
123 continue
124 # Store name and url
125 icons = favicon.get(url)
126 for i, ico in enumerate(icons):
127 d['%s-%s' % (name, i)] = ico.url
131 aux = IconHTML(d, verbose=1)
132 aux
Total running time of the script: ( 2 minutes 39.772 seconds)