.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/guis/imgui_legend.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__gallery_guis_imgui_legend.py: ImGUI Legend ============ A legend for a sine, a cosine, and infinite lines marking the phase. Each graphic makes and keeps its own legend item, and the item follows the graphic, so recoloring the sine recolors its swatch. .. GENERATED FROM PYTHON SOURCE LINES 8-57 .. image-sg:: /_gallery/guis/images/sphx_glr_imgui_legend_001.webp :alt: imgui legend :srcset: /_gallery/guis/images/sphx_glr_imgui_legend_001.webp :class: sphx-glr-single-img .. code-block:: Python # test_example = true import numpy as np import fastplotlib as fpl from fastplotlib.ui import Legend figure = fpl.Figure(size=(700, 560)) xs = np.linspace(0, 4 * np.pi, 400, dtype=np.float32) sine = figure[0, 0].add_line(np.column_stack([xs, np.sin(xs)]), colors="w", name="sine") cosine = figure[0, 0].add_line( np.column_stack([xs, np.cos(xs)]), colors="cyan", name="cosine" ) # vertical lines at every half period phase = figure[0, 0].add_inf_line( np.arange(0, 4.5 * np.pi, np.pi / 2, dtype=np.float32), axis="x", colors="gray", thickness=1, dash_pattern="--", name="phase", ) # a graphic with one color is one entry, labelled by the graphic's name legend = Legend( [ sine.create_legend_item(), cosine.create_legend_item(), phase.create_legend_item(), ] ) figure.add_imgui_window( legend, location="floating", rect=(0.8, 0.05, 0, 0), title="legend" ) figure.show(maintain_aspect=False) # the entry follows the graphic, its swatch turns yellow along with the line sine.colors = "r" # NOTE: fpl.loop.run() should not be used for interactive sessions # See the "JupyterLab and IPython" section in the user guide if __name__ == "__main__": print(__doc__) fpl.loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.132 seconds) .. _sphx_glr_download__gallery_guis_imgui_legend.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: imgui_legend.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: imgui_legend.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_