.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "11_demos\itom\embeddedMatplotlib\demo_matplotlibGui.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_11_demos_itom_embeddedMatplotlib_demo_matplotlibGui.py: Matplotlib embedded in GUI ============================= This examples shows how the ``matplotlib`` can be integrated into a ``GUI`` based on the ``MatplotlibPlot`` Qt Designer plugin. .. GENERATED FROM PYTHON SOURCE LINES 7-15 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from itom import ui .. GENERATED FROM PYTHON SOURCE LINES 17-18 Plots spines into the ``MatplotlibPlot`` Qt Designer plugin. .. GENERATED FROM PYTHON SOURCE LINES 18-54 .. code-block:: Python def plotDroppedSpines(): """ plot taken from matplotlib example 'spines_demo_dropped.py' """ canvas = gui.plot # reference to matplotlibPlot widget # if the same figure object in the matplotlib figure manager should # be reused, since it is assigned to the pre-defined canvas in the ui # file, you need to always set a unique number (can be arbitrary, but unique) fig = plt.figure(num=3, canvas=canvas) if len(fig.axes) == 0: # create a new subplot in the figure ax = fig.add_subplot(111) else: # reuse the existing first subplot ax = fig.axes[0] ax.clear() image = np.random.uniform(size=(10, 10)) ax.imshow(image, cmap=plt.cm.gray, interpolation="nearest") ax.set_title("dropped spines") # Move left and bottom spines outward by 10 points ax.spines["left"].set_position(("outward", 10)) ax.spines["bottom"].set_position(("outward", 10)) # Hide the right and top spines ax.spines["right"].set_visible(False) ax.spines["top"].set_visible(False) # Only show ticks on the left and bottom spines ax.yaxis.set_ticks_position("left") ax.xaxis.set_ticks_position("bottom") plt.show() .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. image:: ../../_static/demoMatplotlibGUI_1.png :width: 75% .. GENERATED FROM PYTHON SOURCE LINES 60-61 Plots a sine curve into the ``MatplotlibPlot`` Qt Designer plugin. .. GENERATED FROM PYTHON SOURCE LINES 61-94 .. code-block:: Python def plotSine(): """ plots sine, taken from matplotlib gallery examples """ t = np.arange(0.0, 1.0, 0.01) s = np.sin(2 * np.pi * t) canvas = gui.plot # reference to matplotlibPlot widget fig = plt.figure(num=3, canvas=canvas) if len(fig.axes) == 0: # create a new subplot in the figure ax = fig.add_subplot(111) else: # reuse the existing first subplot ax = fig.axes[0] ax.clear() ax.plot(t, s) plt.show() gui = ui("matplotlibGui.ui", type=ui.TYPEWINDOW) gui.btnSine.connect("clicked()", plotSine) gui.btnDroppedSpines.connect("clicked()", plotDroppedSpines) gui.show() # if you call this script for the second time, the given figure-num (3) # is already in used for the lastly closed figure. Therefore also tell # matplotlib to close this figure handle. plt.close(3) .. GENERATED FROM PYTHON SOURCE LINES 95-97 .. image:: ../../_static/demoMatplotlibGUI_2.png :width: 75% .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.032 seconds) .. _sphx_glr_download_11_demos_itom_embeddedMatplotlib_demo_matplotlibGui.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_matplotlibGui.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_matplotlibGui.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_matplotlibGui.zip `