.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/Benchmarks/plot_benchmark_comparison.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_Benchmarks_plot_benchmark_comparison.py: Plot Update Comparison ====================== There are a couple of different "costs" asscociated with rendering plots and images. There is usually a Python-side cost as well as a browser-side rendering cost. We've broken down those two costs here comparing different libraries for the first cost. The second is harder to measure. We've done it for anyplotlib but doing it for `ipympl`, bokeh and plotly is a little more difficult. * **Python pre-render** — everything that happens in the Python process before bytes reach the browser (``timeit``-measured, no browser needed). * **JS canvas render** — the actual canvas paint time measured inside headless Chromium via Playwright (anyplotlib only; see the third and fourth charts). .. note:: The Python-side timings are pure-Python ``timeit`` benchmarks — no browser is involved. The JS render timings use Playwright's ``requestAnimationFrame`` loop and ``window._aplTiming`` to measure inter-frame intervals in a real Chromium renderer. What each Python measurement covers ------------------------------------- +---------------+---------------------------------------------------------------+ | Library | What is timed | +===============+===============================================================+ | anyplotlib | ``plot.set_data(data)`` — float → uint8 normalise → base64 | | | encode → LUT rebuild → state-dict assembly → json.dumps → | | | traitlet dispatch to JS renderer. | +---------------+---------------------------------------------------------------+ | ipympl | ``im.set_data(data); fig.canvas.draw()`` — fully rasterises | | | the figure to an Agg pixel buffer, then encodes it as a PNG | | | blob ready for the ipympl comm channel. This is the complete | | | Python-side cost before the PNG is sent to the browser. | +---------------+---------------------------------------------------------------+ | Plotly | ``fig.data[0].z = data.tolist(); fig.to_json()`` — builds the | | | full JSON blob that Plotly.js receives; every float becomes a | | | decimal string. Plotly.js WebGL/SVG render is additional. | +---------------+---------------------------------------------------------------+ | Bokeh | ``source.data = {"image": [data]}; json_item(p)`` — builds | | | the full JSON document patch that Bokeh.js receives. Canvas | | | render is additional. | +---------------+---------------------------------------------------------------+ .. GENERATED FROM PYTHON SOURCE LINES 48-49 .. code-block:: Python :dedent: 1 .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 440-443 --------------------------------------------------------------------------- 2-D image update (Python pre-render, all four libraries) --------------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 443-445 .. code-block:: Python :dedent: 1 .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 464-467 --------------------------------------------------------------------------- 1-D line update (Python pre-render, all four libraries) --------------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 467-469 .. code-block:: Python :dedent: 1 .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 489-511 anyplotlib: Python prep vs JS canvas render ------------------------------------------- The two charts above show only the Python-side cost. The charts below add the JS render time for anyplotlib measured inside a real Chromium renderer via Playwright (``window._aplTiming`` populated by ``_recordFrame()`` in ``figure_esm.js``). The sum of both bars is the **total time-to-pixel** for an anyplotlib update. For ipympl, Plotly, and Bokeh the browser render cost is additional but not captured here — measuring it requires running their respective JS engines in a live browser session. .. note:: If Playwright is not installed the JS bars are absent (zero height) and a ``UserWarning`` is emitted at import time. Install Playwright (``pip install playwright && playwright install chromium``) to populate the JS timing columns. 2D Image Plotting Costs ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 511-513 .. code-block:: Python :dedent: 1 .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 535-537 Scatter Plotting Costs ------------------------- .. rst-class:: sphx-glr-timing **Total running time of the script:** (2 minutes 54.019 seconds) .. _sphx_glr_download_auto_examples_Benchmarks_plot_benchmark_comparison.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_benchmark_comparison.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_benchmark_comparison.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_benchmark_comparison.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_