Skip to content

Images in notebook are rendered too large #522

@grst

Description

@grst

Describe the bug

context
When including a plot in a jupyter notebook, mystnb renders it way larger than it appears in the jupyter notebook.

expectation
Plot sizes between the original notebook and the mystnb output are consistent

Example:
https://user-images.githubusercontent.com/7051479/240721165-d9159d6b-6ba4-4ef2-b888-7f7f7829a8ea.png

Live version: https://scirpy.scverse.org/en/latest/tutorials/tutorial_io.html#read-an-airr-compliant-rearrangement-table

additional information

@flying-sheep already started some investigation in scverse/cookiecutter-scverse#192:

Matplotlib is configured to use a high DPI, and communicates the metadata about “CSS pixels” via Jupyter cell metadata.

{
  "data": {
    "image/png": "",
    "text/plain": ["<Figure size 480x480 with 1 Axes>"]
  },
  "metadata": {
    "image/png": {
      "height": 398,
      "width": 390
    }
  },
  "output_type": "display_data"
}

It looks like myst-nb adds that metadata to the docutils image node, but somehow it doesn’t end up in the <img> tag.

Possible causes might be

  1. that myst-nb has its own cell.metadata.myst metadata key and might read that one only, not the plain cell.metadata.width/height keys.
  2. that the metadata is unitless and is probably read from the notebook as an int.

Maybe myst-nb adding px to unitless width or height would work? docutils says it wants a “length” or “percentage”, which maybe has to be a string with “px” or “%” at the end

Reproduce the bug

  • Build a documentation with sphinx-book-theme
  • Include a tutorial that contains a matplotlib plot using myst-nb

(If the issue is not obvious, I can try to build a minimal demo repo)

List your environment

Full environment of the RTD build used to generate above documentation:
accessible-pygments-0.0.4
adjusttext-0.8
airr-1.4.1
anndata-0.9.1
asciitree-0.3.3
asttokens-2.2.1
attrs-23.1.0
awkward-2.2.1
awkward-cpp-15
backcall-0.2.0
beautifulsoup4-4.12.2
bleach-6.0.0
changeo-1.3.0
click-8.1.3
comm-0.1.3
contourpy-1.0.7
cycler-0.11.0
debugpy-1.6.7
decorator-5.1.1
defusedxml-0.7.1
distance-0.1.3
docutils-0.19
entrypoints-0.4
executing-1.2.0
fasteners-0.18
fastjsonschema-2.17.1
fonttools-4.39.4
greenlet-2.0.2
h5py-3.8.0
igraph-0.10.4
importlib_metadata-6.6.0
ipykernel-6.23.1
ipython-8.14.0
jedi-0.18.2
joblib-1.2.0
jsonschema-4.17.3
jupyter-cache-0.6.1
jupyter-client-8.2.0
jupyter-core-5.3.0
jupyterlab-pygments-0.2.2
jupytext-1.14.5
kiwisolver-1.4.4
latexcodec-2.0.1
leidenalg-0.9.1
Levenshtein-0.21.0
llvmlite-0.40.0
markdown-it-py-2.2.0
matplotlib-3.7.1
matplotlib-inline-0.1.6
mdit-py-plugins-0.3.5
mdurl-0.1.2
mistune-2.0.5
mizani-0.9.2
mudata-0.2.2
muon-0.1.3
myst-nb-0.17.2
myst-parser-0.18.1
natsort-8.3.1
nbclient-0.7.4
nbconvert-7.4.0
nbformat-5.9.0
nest-asyncio-1.5.6
networkx-3.1
numba-0.57.0
numcodecs-0.11.0
numpy-1.22.4
palettable-3.3.3
pandas-1.5.3
pandocfilters-1.5.0
parasail-1.3.4
parso-0.8.3
patsy-0.5.3
pexpect-4.8.0
pickleshare-0.7.5
platformdirs-3.5.1
plotnine-0.10.1
polyleven-0.8
pooch-1.7.0
prompt-toolkit-3.0.38
protobuf-4.23.2
psutil-5.9.5
ptyprocess-0.7.0
pure-eval-0.2.2
pybtex-0.24.0
pybtex-docutils-1.0.2
pycairo-1.23.0
pydata-sphinx-theme-0.13.3
pynndescent-0.5.10
pyparsing-3.0.9
pyrsistent-0.19.3
python-dateutil-2.8.2
python-igraph-0.10.4
python-levenshtein-0.21.0
pytoml-0.1.21
pytz-2023.3
pyyaml-6.0
pyzmq-25.1.0
rapidfuzz-3.1.0
scanpy-1.9.3
sc-dandelion-0.3.2
scikit-learn-1.2.2
scipy-1.10.1
scirpy-0.13.0rc2.dev17+g1f3eb33
seaborn-0.12.2
session-info-1.0.0
setuptools-scm-7.1.0
six-1.16.0
soupsieve-2.4.1
sphinx-5.3.0
sphinx-autodoc-typehints-1.23.0
sphinx-book-theme-1.0.1
sphinxcontrib-bibtex-2.5.0
sphinx-copybutton-0.5.2
sqlalchemy-2.0.15
squarify-0.4.3
stack-data-0.6.2
statsmodels-0.14.0
stdlib_list-0.8.0
tabulate-0.9.0
texttable-1.6.7
threadpoolctl-3.1.0
tinycss2-1.2.1
toml-0.10.2
tomli-2.0.1
tornado-6.3.2
tqdm-4.65.0
traitlets-5.9.0
typing-extensions-4.6.3
umap-learn-0.5.3
wcwidth-0.2.6
webencodings-0.5.1
zarr-2.14.2
zipp-3.15.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions