Note
Go to the end to download the full example code.
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.

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: <LazySignal2D, title: , dimensions: (10|256, 256)>
Navigator initialized: [<LazySignal1D, title: , dimensions: (|10)>]
resolved icons /Users/runner/work/spyde/spyde/spyde/qt/assets/icons/minimize.svg
False
{<spyde.drawing.plots.plot.Plot(0x15e586f40, parent=0x15e5851c0, pos=12,12, flags=(ItemUsesExtendedStyleOption|ItemSendsGeometryChanges)) at 0x15f30acc0>: [(0, 0)]} after adding item at ( 0 , 0 )
Adding navigation plot states for signals: [<LazySignal1D, title: , dimensions: (|10)>]
{<spyde.drawing.plots.plot_window.PlotWindow(0x15bf35ac0) at 0x15e2f0f00>: {}}
Adding navigation plot state for plot: <spyde.drawing.plots.plot.Plot(0x15e586f40, parent=0x15e5851c0, pos=12,12, flags=(ItemUsesExtendedStyleOption|ItemSendsGeometryChanges)) at 0x15f30acc0>
Plot states {}
SubTB: [[]]
SubTB: [[], []]
SubTB: [[], [], []]
SubTB: [[], [], [], []]
SubTB: [[], [], [], [], []]
Adding toolbar action: Reset to right toolbar
Function: functools.partial(<function reset_view at 0x14bc21760>, 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(<function zoom_in at 0x14bc202c0>, 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(<function zoom_out at 0x14bc216c0>, 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(<function add_selector at 0x14bc22520>, 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(<function toggle_navigation_plots at 0x14bc22660>, action_name='Select Navigator'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/navigator.svg, Toggle: True, Params: {}
Initialized PlotState: <PlotState signal=<LazySignal1D, title: , dimensions: (|10)>, dimensions=1, dynamic=False>
updating data for static plot state... [<Future: pending, key: finalize-hlgfinalizecompute-d9a1ee1f3b4f44cf9105f8cd2275c8ca>]
Updating plot data [<Future: pending, key: finalize-hlgfinalizecompute-d9a1ee1f3b4f44cf9105f8cd2275c8ca>] force= False
The view range: [[-0.07312724241271307, 1.073127242412713], [-0.07602859212697055, 1.0760285921269706]]
Setting current data to: <Future: pending, key: finalize-hlgfinalizecompute-d9a1ee1f3b4f44cf9105f8cd2275c8ca>
Plot data updated.
Showing selectors for plot_window: <spyde.drawing.plots.plot_window.PlotWindow(0x15bf35ac0) at 0x15e2f0f00>
Current visible selectors: []
Multiplot manager: {<spyde.drawing.plots.plot_window.PlotWindow(0x15bf35ac0) at 0x15e2f0f00>: []}
visible selectors: []
Updating axes widget, plot state: <PlotState signal=<LazySignal1D, title: , dimensions: (|10)>, 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.': '--'}}
<pyqtgraph.graphicsItems.ImageItem.ImageItem(0x15e3b3be0, pos=0,0, flags=(ItemSendsGeometryChanges)) at 0x15f342200>
Showing toolbars for plot state: <PlotState signal=<LazySignal1D, title: , dimensions: (|10)>, dimensions=1, dynamic=False>
Adding navigation selector to plot window: <spyde.drawing.plots.plot_window.PlotWindow(0x15bf35ac0) at 0x15e2f0f00> with dim: 1
Plot window level: 1 children dict: {}
{<spyde.drawing.plots.plot_window.PlotWindow(0x15bf35ac0) at 0x15e2f0f00>: {}}
1
resolved icons /Users/runner/work/spyde/spyde/spyde/qt/assets/icons/minimize.svg
False
{<spyde.drawing.plots.plot.Plot(0x15e3cf490, parent=0x15bbf95b0, pos=12,12, flags=(ItemUsesExtendedStyleOption|ItemSendsGeometryChanges)) at 0x15d6b9bc0>: [(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(<function add_virtual_image at 0x15e215760>, action_name='add_virtual_image'), '/Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/zoom.svg', 'Add Virtual Image', False, {})]
SubTB: [[], [], [], [], [], [], [], [(functools.partial(<function add_virtual_image at 0x15e215760>, 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(<function reset_view at 0x14bc21760>, 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(<function zoom_in at 0x14bc202c0>, 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(<function zoom_out at 0x14bc216c0>, 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(<function add_fft_selector at 0x14bc225c0>, 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(<function toggle_signal_tree at 0x14bc22b60>, 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(<function rebin2d at 0x14bc22ac0>, 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(<function center_zero_beam at 0x15e2156c0>, 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(<function virtual_imaging at 0x15e2154e0>, action_name='Virtual Imaging'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/virtual_image_color.svg, Toggle: True, Params: {}
[(functools.partial(<function add_virtual_image at 0x15e215760>, 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: <PlotState signal=<LazySignal2D, title: , dimensions: (10|256, 256)>, dimensions=2, dynamic=True>
All Items: [<pyqtgraph.graphicsItems.ImageItem.ImageItem(0x15e3f71e0, parent=0x15e3d0930, pos=0,0, flags=(ItemSendsGeometryChanges)) at 0x15f370280>]
Updating child plot based on navigation selection with indices: [0]
Current signal shape (10, 256, 256)
Cache in shared memory: True
Updating plot data <Future: pending, key: write_shared_array-55cf06d1f7d13e563f575e599f530f24> 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: <Future: pending, key: write_shared_array-55cf06d1f7d13e563f575e599f530f24>
Plot data updated.
updating data for dynamic plot state... <Future: pending, key: write_shared_array-55cf06d1f7d13e563f575e599f530f24>
Updating plot data <Future: pending, key: write_shared_array-55cf06d1f7d13e563f575e599f530f24> force= False
Setting current data to: <Future: pending, key: write_shared_array-55cf06d1f7d13e563f575e599f530f24>
Plot data updated.
Updating selectors for new image transform: []
50.0 <undefined>
50.0 <undefined>
Showing selectors for plot_window: <spyde.drawing.plots.plot_window.PlotWindow(0x15bd22f30) at 0x15f343840>
Current visible selectors: []
Multiplot manager: {<spyde.drawing.plots.plot_window.PlotWindow(0x15bf35ac0) at 0x15e2f0f00>: [<spyde.drawing.selector.IntegratingLinearRegionSelector object at 0x14bc9d3d0>]}
No navigation selectors for this plot window.
visible selectors: []
Updating axes widget, plot state: <PlotState signal=<LazySignal2D, title: , dimensions: (10|256, 256)>, dimensions=2, dynamic=True>
Removing selector control widgets for plot_window: <spyde.drawing.plots.plot_window.PlotWindow(0x15bf35ac0) at 0x15e2f0f00>
Nav sel {<spyde.drawing.plots.plot_window.PlotWindow(0x15bf35ac0) at 0x15e2f0f00>: [<spyde.drawing.selector.IntegratingLinearRegionSelector object at 0x14bc9d3d0>]}
Plot win <spyde.drawing.plots.plot_window.PlotWindow(0x15bf35ac0) at 0x15e2f0f00>
<pyqtgraph.graphicsItems.ImageItem.ImageItem(0x15e3f71e0, parent=0x15e3d0930, pos=0,0, flags=(ItemSendsGeometryChanges)) at 0x15f370280>
Showing toolbars for plot state: <PlotState signal=<LazySignal2D, title: , dimensions: (10|256, 256)>, 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 <Future: pending, key: write_shared_array-55cf06d1f7d13e563f575e599f530f24> force= False
Setting current data to: <Future: pending, key: write_shared_array-55cf06d1f7d13e563f575e599f530f24>
Plot data updated.
Created Signal Tree with root signal: <LazySignal2D, title: , dimensions: (10|256, 256)>
Signal Tree Created
Adding navigator signal: Temperature
Adding navigation plot states for signals: [<Signal1D, title: Temperature, dimensions: (|10)>]
{<spyde.drawing.plots.plot_window.PlotWindow(0x15bf35ac0) at 0x15e2f0f00>: {<spyde.drawing.plots.plot_window.PlotWindow(0x15bd22f30) at 0x15f343840>: {}}}
Adding navigation plot state for plot: <spyde.drawing.plots.plot.Plot(0x15e586f40, parent=0x15e5851c0, pos=12,12, flags=(ItemUsesExtendedStyleOption|ItemSendsGeometryChanges)) at 0x15f30acc0>
Plot states {<LazySignal1D, title: , dimensions: (|10)>: <PlotState signal=<LazySignal1D, title: , dimensions: (|10)>, dimensions=1, dynamic=False>}
SubTB: [[]]
SubTB: [[], []]
SubTB: [[], [], []]
SubTB: [[], [], [], []]
SubTB: [[], [], [], [], []]
Adding toolbar action: Reset to right toolbar
Function: functools.partial(<function reset_view at 0x14bc21760>, 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(<function zoom_in at 0x14bc202c0>, 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(<function zoom_out at 0x14bc216c0>, 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(<function add_selector at 0x14bc22520>, 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(<function toggle_navigation_plots at 0x14bc22660>, action_name='Select Navigator'), Icon: /Users/runner/work/spyde/spyde/spyde/drawing/toolbars/icons/navigator.svg, Toggle: True, Params: {}
Initialized PlotState: <PlotState signal=<Signal1D, title: Temperature, dimensions: (|10)>, dimensions=1, dynamic=False>
Emitting Future, finalize-hlgfinalizecompute-d9a1ee1f3b4f44cf9105f8cd2275c8ca for plot: <spyde.drawing.plots.plot.Plot(0x15e586f40, parent=0x15e5851c0, pos=12,12, flags=(ItemUsesExtendedStyleOption|ItemSendsGeometryChanges)) at 0x15f30acc0>
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.

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.

# 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.

Updating navigator plot image rectangle for: <spyde.drawing.plots.plot_window.PlotWindow(0x15bf35ac0) at 0x15e2f0f00>
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'
Finally, we can see the main window with the updated axis labels and scales reflected in the plot.
Total running time of the script: (0 minutes 2.652 seconds)