.. only:: html
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here ` to download the full example code
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_examples_imaging_plotting.py:
Make a plot, save, and show it (with and without blocking)
==========================================================
1) Regular plot show and save
2) Same but interactive and iterative (plt.ion() -> child threads, multi figs)
3) Use Bokeh to do some magic in a browser and draw connection to REST endpoint
for dashboard. Basically mention how we'll likely use bokeh for graphs.
First let's import our basic libraries
.. code-block:: default
import numpy as np
import matplotlib.pyplot as plt
import imagepypelines as ip
We'll also need to set up a few blocks
.. code-block:: default
# A quick function which plots a line and styles it using plt.plot()'s kwargs
@ip.blockify(batch_type="all", void=True) # plot=True -> sets batch type to "all" for similar UX? Not sure if worth aliasing
def line_plot(x, y, color="r"):
fig = plt.figure()
plt.plot(x, y, color=color)
plt.show()
line_plot_red = line_plot.tweak(color='r')
line_plot_green = line_plot.tweak(color='g')
line_plot_blue = line_plot.tweak(color='b')
tasks_verbose = {"x": ip.Input(),
"y": ip.Input(),
"red": (line_plot_red, "x", "y"),
"green": (line_plot_green, "x", "y"),
"blue": (line_plot_blue, "x", "y")
}
tasks_tweaked = {"x": ip.Input(),
"y": ip.Input(),
"red": (line_plot.tweak(color='r'), "x", "y"),
"green": (line_plot.tweak(color='g'), "x", "y"),
"blue": (line_plot.tweak(color='b'), "x", "y")
}
# Normal functionality
line_plot([1,2,3], [4,5,6])
# Pipeline functionality - pre-defining separate instances
plotting = ip.Pipeline(tasks_verbose)
plotting([1,2,3],[2,4,6])
# Pipeline functionality - defining in place
plotting = ip.Pipeline(tasks_tweaked)
plotting([1,2,3],[2,4,6])
.. rst-class:: sphx-glr-horizontal
*
.. image:: /examples/imaging/images/sphx_glr_plotting_001.png
:alt: plotting
:class: sphx-glr-multi-img
*
.. image:: /examples/imaging/images/sphx_glr_plotting_002.png
:alt: plotting
:class: sphx-glr-multi-img
*
.. image:: /examples/imaging/images/sphx_glr_plotting_003.png
:alt: plotting
:class: sphx-glr-multi-img
*
.. image:: /examples/imaging/images/sphx_glr_plotting_004.png
:alt: plotting
:class: sphx-glr-multi-img
*
.. image:: /examples/imaging/images/sphx_glr_plotting_005.png
:alt: plotting
:class: sphx-glr-multi-img
*
.. image:: /examples/imaging/images/sphx_glr_plotting_006.png
:alt: plotting
:class: sphx-glr-multi-img
*
.. image:: /examples/imaging/images/sphx_glr_plotting_007.png
:alt: plotting
:class: sphx-glr-multi-img
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
{'x': [1, 2, 3], 'y': [2, 4, 6], 'red': None, 'green': None, 'blue': None}
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 0.635 seconds)
.. _sphx_glr_download_examples_imaging_plotting.py:
.. only :: html
.. container:: sphx-glr-footer
:class: sphx-glr-footer-example
.. container:: sphx-glr-download sphx-glr-download-python
:download:`Download Python source code: plotting.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plotting.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_