.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/general/editing_axes.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_examples_general_editing_axes.py: Changing Scales and Axes ======================== This example demonstrates how to modify the scales and axes of a plot. These are rendered as QLabels but can be edited by left-clicking on them which will change them into QLineEdits for text input. .. GENERATED FROM PYTHON SOURCE LINES 9-12 .. code-block:: Python :dedent: 1 .. image-sg:: /examples/general/images/sphx_glr_editing_axes_001.png :alt: editing axes :srcset: /examples/general/images/sphx_glr_editing_axes_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none CPU Count: 3 [startup] Plot update worker thread start completed in 0.0 ms [startup] Plot control dock creation completed in 9.3 ms [startup] Inst. control dock creation completed in 60.6 ms Starting Dask LocalCluster with 1 workers, and 1 threads per worker Creating Data Dialog accepted Data created Creating Signal Tree for signal Dask cluster ready. Dashboard: http://127.0.0.1:8787/status Initializing navigator for root signal: Navigator initialized: [] resolved icons /Users/runner/work/spyde/spyde/spyde/qt/assets/icons/minimize.svg False {: [(0, 0)]} after adding item at ( 0 , 0 ) Adding navigation plot states for signals: [] {: {}} Adding navigation plot state for plot: Plot states {} SubTB: [[]] SubTB: [[], []] SubTB: [[], [], []] SubTB: [[], [], [], []] SubTB: [[], [], [], [], []] Adding toolbar action: Reset to right toolbar Function: functools.partial(, action_name='Reset'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/fullsize.svg, Toggle: False, Params: {} Adding toolbar action: Zoom In to right toolbar Function: functools.partial(, action_name='Zoom In'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/zoom.svg, Toggle: False, Params: {} Adding toolbar action: Zoom Out to right toolbar Function: functools.partial(, action_name='Zoom Out'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/zoomout.svg, Toggle: False, Params: {} Adding toolbar action: Add Selector to right toolbar Function: functools.partial(, action_name='Add Selector'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/add_selector.svg, Toggle: False, Params: {} Adding toolbar action: Select Navigator to right toolbar Function: functools.partial(, action_name='Select Navigator'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/navigator.svg, Toggle: True, Params: {} Initialized PlotState: , dimensions=1, dynamic=False> updating data for static plot state... [] Updating plot data [] force= False The view range: [[-0.07312724241271307, 1.073127242412713], [-0.07602859212697055, 1.0760285921269706]] Setting current data to: Plot data updated. Showing selectors for plot_window: Current visible selectors: [] Multiplot manager: {: []} visible selectors: [] Updating axes widget, plot state: , dimensions=1, dynamic=False> Getting metadata widget Processing subsection: Instrument Metadata Processing property: Mag with value: {'key': 'Acquisition_instrument.TEM.magnification', 'type': 'float', 'description': 'The magnification factor of the instrument.', 'default': '--', 'units': 'x'} Resolved value for Mag: -- x Processing property: Acc. Volt. with value: {'key': 'Acquisition_instrument.TEM.beam_energy', 'type': 'float', 'description': 'The acceleration voltage used during imaging.', 'default': '--', 'units': 'kV'} Resolved value for Acc. Volt.: -- kV Processing property: Cam. Len. with value: {'key': 'Acquisition_instrument.TEM.camera_length', 'type': 'float', 'description': 'The camera length setting of the instrument.', 'default': '--', 'units': 'mm'} Resolved value for Cam. Len.: -- mm Processing property: Conv. Angle with value: {'key': 'Acquisition_instrument.TEM.convergence_angle', 'type': 'float', 'description': 'The convergence angle of the electron beam.', 'default': '--', 'units': 'mrad'} Resolved value for Conv. Angle: -- mrad Processing subsection: Root Experiment Details Processing property: Name with value: {'key': 'General.title', 'type': 'string', 'description': 'Name of the experiment.', 'default': '--'} Resolved value for Name: Processing property: Date with value: {'key': 'General.date', 'type': 'string', 'description': 'Date when the experiment was conducted.', 'default': 'YYYY-MM-DD'} Resolved value for Date: YYYY-MM-DD Processing property: e-/s with value: {'type': 'float', 'key': 'Acquisition_instrument.TEM.electrons_per_second', 'description': 'Electrons per second.', 'default': '--', 'units': 'e/s'} Resolved value for e-/s: -- e/s Processing property: Dtype with value: {'type': 'string', 'attr': 'root.data.dtype.name', 'description': 'Type of data collected.', 'default': '--'} Resolved value for Dtype: int8 Processing property: Dim. with value: {'type': 'string', 'function': 'root.axes_manager._get_dimension_str()', 'description': 'Dimensions of the collected data.', 'default': '--'} Calling function for property Dim.: root.axes_manager._get_dimension_str() Function root.axes_manager._get_dimension_str() not found. Resolved value for Dim.: -- Processing property: Mode with value: {'type': 'string', 'key': 'Acquisition_instrument.Detector.exposure_mode', 'description': 'Integrating or counting mode.', 'default': '--'} Resolved value for Mode: -- Processing property: Cam. with value: {'type': 'string', 'key': 'Acquisition_instrument.Detector.camera_model', 'description': 'The camera model used for data acquisition.', 'default': '--'} Resolved value for Cam.: -- Final Subsections: {'Instrument Metadata': {'Mag': '-- x', 'Acc. Volt.': '-- kV', 'Cam. Len.': '-- mm', 'Conv. Angle': '-- mrad'}, 'Root Experiment Details': {'Name': '', 'Date': 'YYYY-MM-DD', 'e-/s': '-- e/s', 'Dtype': 'int8', 'Dim.': '--', 'Mode': '--', 'Cam.': '--'}} Showing toolbars for plot state: , dimensions=1, dynamic=False> Adding navigation selector to plot window: with dim: 1 Plot window level: 1 children dict: {} {: {}} 1 resolved icons /Users/runner/work/spyde/spyde/spyde/qt/assets/icons/minimize.svg False {: [(0, 0)]} after adding item at ( 0 , 0 ) Plot states {} SubTB: [[]] SubTB: [[], []] SubTB: [[], [], []] SubTB: [[], [], [], []] SubTB: [[], [], [], [], []] SubTB: [[], [], [], [], [], []] SubTB: [[], [], [], [], [], [], []] add_virtual_image {'add_virtual_image': {'name': 'Add Virtual Image', 'description': 'Adds a virtual image from the 4D-STEM data.', 'icon': 'drawing/toolbars/icons/zoom.svg', 'function': 'spyde.actions.pyxem.add_virtual_image'}} Sub Entries [(functools.partial(, action_name='add_virtual_image'), '/Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/zoom.svg', 'Add Virtual Image', False, {})] SubTB: [[], [], [], [], [], [], [], [(functools.partial(, action_name='add_virtual_image'), '/Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/zoom.svg', 'Add Virtual Image', False, {})]] Adding toolbar action: Reset to right toolbar Function: functools.partial(, action_name='Reset'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/fullsize.svg, Toggle: False, Params: {} Adding toolbar action: Zoom In to right toolbar Function: functools.partial(, action_name='Zoom In'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/zoom.svg, Toggle: False, Params: {} Adding toolbar action: Zoom Out to right toolbar Function: functools.partial(, action_name='Zoom Out'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/zoomout.svg, Toggle: False, Params: {} Adding toolbar action: FFT to right toolbar Function: functools.partial(, action_name='FFT'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/fft.svg, Toggle: False, Params: {} Adding toolbar action: Navigate Signal Tree to right toolbar Function: functools.partial(, action_name='Navigate Signal Tree'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/signal_tree.svg, Toggle: True, Params: {} Adding toolbar action: Rebin to bottom toolbar Function: functools.partial(, action_name='Rebin'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/rebin.svg, Toggle: True, Params: {'scale_x': {'name': 'Scale X', 'type': 'int', 'default': 2}, 'scale_y': {'name': 'Scale Y', 'type': 'int', 'default': 2}} Setting CaretGroup side opposite to toolbar position: bottom Creating CaretParams with parameters: {'scale_x': {'name': 'Scale X', 'type': 'int', 'default': 2}, 'scale_y': {'name': 'Scale Y', 'type': 'int', 'default': 2}} Adding toolbar action: Center Zero Beam to bottom toolbar Function: functools.partial(, action_name='Center Zero Beam'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/center_zero_beam.svg, Toggle: True, Params: {'method': {'name': 'Method', 'type': 'enum', 'default': 'blur', 'options': ['cross_correlate', 'center_of_mass', 'blur', 'interpolate']}, 'sigma': {'name': 'Sigma', 'type': 'float', 'default': 2.0, 'display_condition': {'parameter': 'method', 'value': 'blur'}}, 'min_cc_disk_radius': {'name': 'Min CC Disk Radius', 'type': 'int', 'default': 5, 'display_condition': {'parameter': 'method', 'value': 'cross_correlate'}}, 'max_cc_disk_radius': {'name': 'Max CC Disk Radius', 'type': 'int', 'default': 15, 'display_condition': {'parameter': 'method', 'value': 'cross_correlate'}}, 'signal_slice': {'name': 'Signal Slice', 'type': 'RectangleSelector', 'position': 'centered', 'size': 0.2}, 'make_flat_field': {'name': 'Make Flat Field', 'type': 'bool', 'default': False}} Setting CaretGroup side opposite to toolbar position: bottom Creating CaretParams with parameters: {'method': {'name': 'Method', 'type': 'enum', 'default': 'blur', 'options': ['cross_correlate', 'center_of_mass', 'blur', 'interpolate']}, 'sigma': {'name': 'Sigma', 'type': 'float', 'default': 2.0, 'display_condition': {'parameter': 'method', 'value': 'blur'}}, 'min_cc_disk_radius': {'name': 'Min CC Disk Radius', 'type': 'int', 'default': 5, 'display_condition': {'parameter': 'method', 'value': 'cross_correlate'}}, 'max_cc_disk_radius': {'name': 'Max CC Disk Radius', 'type': 'int', 'default': 15, 'display_condition': {'parameter': 'method', 'value': 'cross_correlate'}}, 'signal_slice': {'name': 'Signal Slice', 'type': 'RectangleSelector', 'position': 'centered', 'size': 0.2}, 'make_flat_field': {'name': 'Make Flat Field', 'type': 'bool', 'default': False}} Adding RectangleSelector ROI for parameter: signal_slice Toolbar available: True toolbar.plot available: True Current signal extent: (0.0, 255.0, 0.0, 255.0) Computed signal center: (127.5, 127.5) Computed signal width: 255.0 Computed ROI size: 51.0 51.0 Computed ROI position: PySide6.QtCore.QPointF(102.000000, 102.000000) Adding RectangleSelector ROI to plot. Adding toolbar action: Virtual Imaging to bottom toolbar Function: functools.partial(, action_name='Virtual Imaging'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/virtual_image_color.svg, Toggle: True, Params: {} [(functools.partial(, action_name='add_virtual_image'), '/Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/zoom.svg', 'Add Virtual Image', False, {})] Restoring plot items for action: Center Zero Beam Initialized PlotState: , dimensions=2, dynamic=True> All Items: [] Updating child plot based on navigation selection with indices: [0] Current signal shape (10, 256, 256) Cache in shared memory: True Updating plot data force= False Setting image data with img [[0. 1. 0. ... 1. 0. 1.] [1. 1. 1. ... 1. 1. 1.] [0. 1. 0. ... 1. 0. 1.] ... [1. 1. 1. ... 1. 1. 1.] [0. 1. 0. ... 1. 0. 1.] [1. 1. 1. ... 1. 1. 1.]] setImage took 0.05ms The view range: [[-0.5404624277456649, 0.5404624277456649], [-0.5000000000000001, 0.5000000000000001]] Setting current data to: Plot data updated. updating data for dynamic plot state... Updating plot data force= False Setting current data to: Plot data updated. Updating selectors for new image transform: [] 50.0 50.0 <undefined> Showing selectors for plot_window: Current visible selectors: [] Multiplot manager: {: []} No navigation selectors for this plot window. visible selectors: [] Updating axes widget, plot state: , dimensions=2, dynamic=True> Removing selector control widgets for plot_window: Nav sel {: []} Plot win Showing toolbars for plot state: , dimensions=2, dynamic=True> /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyqtgraph/graphicsItems/PlotItem/PlotItem.py:615: UserWarning: Item already added to PlotItem, ignoring. warnings.warn('Item already added to PlotItem, ignoring.') Updating Data Updating plot data force= False Setting current data to: Plot data updated. Created Signal Tree with root signal: Signal Tree Created Adding navigator signal: Temperature Adding navigation plot states for signals: [] {: {: {}}} Adding navigation plot state for plot: Plot states {: , dimensions=1, dynamic=False>} SubTB: [[]] SubTB: [[], []] SubTB: [[], [], []] SubTB: [[], [], [], []] SubTB: [[], [], [], [], []] Adding toolbar action: Reset to right toolbar Function: functools.partial(, action_name='Reset'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/fullsize.svg, Toggle: False, Params: {} Adding toolbar action: Zoom In to right toolbar Function: functools.partial(, action_name='Zoom In'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/zoom.svg, Toggle: False, Params: {} Adding toolbar action: Zoom Out to right toolbar Function: functools.partial(, action_name='Zoom Out'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/zoomout.svg, Toggle: False, Params: {} Adding toolbar action: Add Selector to right toolbar Function: functools.partial(, action_name='Add Selector'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/add_selector.svg, Toggle: False, Params: {} Adding toolbar action: Select Navigator to right toolbar Function: functools.partial(, action_name='Select Navigator'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/navigator.svg, Toggle: True, Params: {} Initialized PlotState: , dimensions=1, dynamic=False> Emitting Future, finalize-hlgfinalizecompute-d9a1ee1f3b4f44cf9105f8cd2275c8ca for plot: .. GENERATED FROM PYTHON SOURCE LINES 24-28 After opening the example data, we can see that the plot has default axis labels and scales. By left-clicking on the axis labels (e.g., "X Axis" or "Y Axis"), we can edit them to more meaningful names. Similarly, by left-clicking on the scale labels (e.g., "1.0" on the X-axis), we can change the scale values. This allows us to customize the plot to better represent the data being visualized. .. GENERATED FROM PYTHON SOURCE LINES 28-30 .. code-block:: Python :dedent: 1 .. image-sg:: /examples/general/images/sphx_glr_editing_axes_002.png :alt: editing axes :srcset: /examples/general/images/sphx_glr_editing_axes_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 38-40 There is some limited support for mathematical expressions in the axis labels using LaTeX syntax. For example, we can label an axis as "$nm^{-1}$" to represent nanometers. .. GENERATED FROM PYTHON SOURCE LINES 40-43 .. code-block:: Python :dedent: 1 .. image-sg:: /examples/general/images/sphx_glr_editing_axes_003.png :alt: editing axes :srcset: /examples/general/images/sphx_glr_editing_axes_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 56-61 .. code-block:: Python # After editing the axis labels and scales, the plot now reflects these changes with the updated labels and scales. # This enhances the clarity and interpretability of the plot, making it easier to understand the data being presented. .. image-sg:: /examples/general/images/sphx_glr_editing_axes_004.png :alt: editing axes :srcset: /examples/general/images/sphx_glr_editing_axes_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Updating navigator plot image rectangle for: Traceback (most recent call last): File "/Users/runner/work/spyde/spyde/spyde/signal_tree.py", line 232, in _on_axis_field_edit plot.update_image_rectangle() ^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'PlotWindow' object has no attribute 'update_image_rectangle' .. GENERATED FROM PYTHON SOURCE LINES 69-70 Finally, we can see the main window with the updated axis labels and scales reflected in the plot. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.652 seconds) .. _sphx_glr_download_examples_general_editing_axes.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: editing_axes.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: editing_axes.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: editing_axes.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_