Spectra Trace Offset and Graph Size Tools

This project provides two panels and menu functions for quickly changing traces and common graphs style options. The panels always operate on the topmost graph. You can select another graph and then switch back to the panel, which updates all settings automatically. The panels do not modify the underlying data unless explicitly told so.

The original code and the idea for the Offset Traces right-click menu has been kindly provided by Tony (https://www.wavemetrics.com/user/tony) from his StackTraces toolset.

I tried my best to test everything thoroughly, but sometimes bugs slip through. Bug reports and suggestions for new features are always welcome.

The Graph Size panel

Use this panel to change the graph size, margins or axis labels and to apply style macros quickly. All changes are live. Settings can also be copied and applied to other graphs. Start the panel by selecting 'Spectra Tools' -> 'Graph Size Panel ...' from menu bar or executing:

BuildTraceOffsetPanel()

Here is a quick overview of all functions:

In the topmost area you can set margins, plot area and graph sizes. In short, most settings of the Modify Graph dialog are recreated here for quick access. Numbers rendered in bold font show that these properties are locked to a specific value. In other words, these values will not change/cannot be changed dynamically, for example, by scaling the graph with the mouse. Insert 0 (zero) into the respective field to unlock the value. If 'Keep Auto Mode' is checked, then changing the graph or plot area sizes will not lock these values. Margin sizes will  get always locked upon changing the value, since margins have to a predefined size in Auto mode. The font control will change the global font size (as found in the Modify Graph dialog). Font sizes specified for individual axes etc. override this setting. The exp. control changes the magnification setting of the graph, which is useful to enlarge / shrink graphs without changing their (physical) size.

The Aspect Ratio setting, as the name implies, locks the aspect ratio of the graph (plot area) to certain common presets, such as 3:2 or 16:9.

The Format drop-down menu allows to quickly set the graph to common formats (useful for copy-pasting or graphics export):

  • Paper Half / Full: Publication size figures of one column (3.25 inch) or double-column (7 inch) width.
  • PPT 4:3 / 16:9: Power-point size plots for 4:3 or 16:9 format slides (full and half each).

The Copy and Paste buttons are for copying margin and graph size settings to another graph. Press Copy to save the current settings, then bring another graph to the top and press Paste.

The bottom-most area is for applying graph style macros. Select the desired style in the drop-down box and press Apply. The style can be reverted to the previous style for the current graph by pressing Revert. This function only saves the state of the current graph when pressing Apply. Undo states for multiple graphs are not saved.

The Copy Style button saves the current style of the top graph to apply the same style to another graph later. If the 'w/ Axis Scaling' checkbox is active then the current X and Y axis range limits are copied and applied as well. A 'Copied Style' will appear in the list after pressing the button, which can be applied to other graphs with the Apply button just as a regular style macro.

The project includes a standard style, named 'BoxStyle', and several label style macros, which apply labels from a few spectroscopic techniques to the graph. Holding 'ctrl' (Win) / 'command' (Mac) will suppress the ticks and labels on the left axis while applying the BoxStyle style, and will label the x axis with 'Binding energy' instead of 'Kinetic energy' while applying the PKE_Label style.

Graph and Traces Right-click Menus

New functionality has been added to the graph's right-click menu (which appears when you right-click on an empty area of the graph):

  •     Left: Autoscale Only Visible - Sets 'Zero isn't special' scaling mode for the y axis..
  •     Left: Autoscale From Zero - Sets 'Autoscale from zero' scaling mode for the y axis.
  •     Traces: Undo All Scaling - Removes multipliers from all traces.
  •     Traces: Undo All Offsets - Removes offsets from all traces.

The Offset Traces submenu contains the following options. All these options work with the current y-axis range of the graph. You may want to increase the y-range before applying these options for maximum effect.

  •     Spread Traces Across y Range - Adds offsets to each trace to distribute traces across the current y-range (initial offsets are preserved).
  •     Spread Traces: Equal Offset - Adds equal offset steps to each trace to distribute traces across the current y-range.
  •     Spread Traces: Equal Gap - Adds offsets to each trace to distribute traces across the current y-range in a way which keeps the gap between traces (= maximum of previous trace to minimum of next trace) constant.

Furthermore, the traces right-click menu (when you right-click on a trace) contains the following additional functions:

  • y-Offset: Align Traces Here - Sets the offset of all traces so that they align at the cursor position. Hold ctrl / command to align all traces to y = 0.
  • y-Scale: Match Traces Here - Sets the multiplicator of all traces so that they align at the cursor position. Hold ctrl / command to scale all traces to y = 1.
  • y-Order Traces Here - Sorts the traces (trace display order in the graph) so that the y-value at the cursor position is in ascending order. Hold ctrl / command to sort in descending order.

Waterfall plots and the Modify Traces panel

The main purpose of the Modify Traces panel is to work with (pseudo) waterfall plots. First, note that Igor Pro also provides an official package for creating waterfall plots (See: Windows -> New -> Packages -> Waterfall Plot). The current project instead creates (pseudo-)waterfall plots by offsetting traces in a graph, and is not compatible with the official Waterfall Plot package.

The provided menu entries inside the Spectra Tools menu are:

  • Waterfall Plot of 2D Data or Folder - Creates a pseudo-waterfall plot from a 2D wave or a folder of 1D waves selected in the Data Browser (select one 1D wave inside the folder for the latter).
  • Normalize Traces to 1 - Scales all traces in the top graph to y = 1. The baseline is set to 0 unless 'shift' is pressed while selecting this entry.
  • Normalize Traces to 1 at Cursor A - Scales all traces in the top graph to y = 1 at cursor A (if set on the graph). The baseline is set to 0 unless 'shift' is pressed.
  • Normalize Traces to Area - Scales all traces to unit area.
  • Quick Colorize Traces - Applies up to 13 different colors to the traces in the top graph.

    Start the Modify Traces panel by going to 'Spectra Tools' -> 'Trace Offset Panel ...' or execute:

    BuildTraceOffsetPanel()

    A quick overview of all functions is found below:

    The left column is for offsetting multiple traces together (such as in a waterfall graph) while the right side is for modifying the offset of individual traces selected by cursors. There are two modes: The offsets are either set (= the relative offset between traces will be exactly the inserted value) or added (the relative offset is added to the already set trace offsets).

    The Colorize button works als on images but otherwise the panel is not very useful for image plots.

    The Profile drop-down list can be used to append an 1D wave vertically. This is useful to show a certain trend or integrated data which is representative of the traces shown in the graph, and at the same time serves as the (third) waterfall axis. The axis of this profile is scaled together with the top trace when Y-offsetting traces. A waterfall with an attached profile looks, for example, like this:

    Offsetting individual traces (right): The trace to work on is selected with a cursor (A-D). The active cursor can be moved between traces with the Prev Trace and Next Trace buttons.

    New in version 1.3: Press the Cursor button to add a new cursor to the current graph until all four cursors are set.

    The Apply All to Data and Apply to This Data buttons will (try to) apply the offsets and scaling to the data (and then reset the graph offsets). This will overwrite the original data, so be careful! The applied offsets and multipliers are saved in the wave's note, which makes it in principle possible to reverse this action (this is not provided at the moment, but can be easily added if there is demand). Note that applying x-offsets to XY-data where all traces have the same x wave will likely give undesired results: Since the x wave is modified all traces will shift over by the set x offset. These buttons do not work for graphs displaying 2D data sets, at the moment.

    Keyboard shortcuts:

    Some aspects of the Individual Traces controls (right side of the panel) can be controlled with the keyboard when the panel is in focus:

    • The a, b, c or d keys select cursor A, B, C or D.
    • h sets the active cursor to the maximum (high point) of the currently selected trace.
    • l (small L) sets the cursor to the minimum (low point) of the trace.
    • page up / page down moves the cursor to the next / previous trace in the graph.
    • The left / right arrow keys shifts the trace left / right in x direction
    • The up / down arrow keys shifts the trace up / down in y direction
    • Press the left / right arrow keys while holding the ctrl / command key to scale the trace in x direction
    • Press the up / down arrow keys while holding the ctrl / command key to scale the trace in y direction

    The dx/dy fields and user-provided update functions

    The dx/dy fields at the bottom of the Individual Traces area are used to add (+) or subtract (-) constant values to the x / y offset of the selected trace using the respective buttons. Inserting a negative value will additionally invert the respective axis (the trace is flipped). The main use is to add or subtract pre-defined offsets such as the photon energy of a measured spectrum (in this case, addition/subtraction will remove or include the photon energy value to the energy axis).

    These fields can be pre-filled with information from the data using the TraceTool_FetchXShift() and TraceTool_FetchYShift() functions, which are called upon selecting a different trace or graph. You can modify these two functions directly at the beginning of the procedure file, but it is more convenient to provide your own code in a separate file or inside the experiment environment. Use the Override keyword in front of the Function statement to override the standard definitions inside the package. The following code shows the current implementation inside the project’s procedure, which is used to extract the used photon energy value from measurement data:

    Static Function TraceTool_FetchXShift(input, unit)
        Wave input
        String &unit        // optional unit string
        Variable xShift = NaN   // the shift value
        Variable neg = 1
        String notes = note(input)
        String energy = StringByKey("Xray energy", notes, "=","\r") // find the photon energy
        if (!strlen(energy))
            energy = StringByKey("photon energy ", notes, "=","\r") // try a different key
        endif
        if (!strlen(energy))
            energy = StringByKey("Excitation Energy", notes, "=","\r")  // try yet a different key
            neg = -1    // this data requires flipping
        endif
        unit = "eV"
        xShift = str2num(energy)*neg
        return xShift   // return NaN for no change and return negative values for flipping the trace
    End

    Static Function TraceTool_FetchYShift(input,unit)
        Wave input
        String &unit
        return NaN
    End

     

    Project Details

    Current Project Release

    Release File: Graph Tools_v1.3.zip
    Version: IGOR.6.30.x-1.3
    Version Date: Sun, 03/28/2021 - 05:40 am
    Version Major: 1
    Version Patch Level: 3
    OS Compatibility: Windows Mac-Intel
    Release Notes:
    • Graph Size panel: The last selected size unit setting is now saved in the current experiment.
    • Trace offset panel: Fixed a few error messages triggered by very old versions of the panel.
    • Trace offset panel: Trace scaling increment steps now get smaller and bigger depending on the order of magnitude of the current scaling (helps to work with very big or small scaling factors).
    • Trace offset panel: Added a button to quickly set a new cursor onto the graph.
    • The currently selected trace name is now displayed in the panel title.
    View All Releases

    nice project.

    a little bug: if cursor is on an image in the top graph an error occurs when the panel is built.

    Tony, thanks! Oops, I have fixed this now. Somehow I had checking for images in place but commented out. I will look into working your StackTraces functions into this package, so that everything is neatly in one place. Thank you for your manual in the other thread.

    EDIT: Now I know why I had commented this out: Because it was not working properly. The current version should work fine with image plots (i.e., no error message). Of course the panel is not that useful for images yet. I have another small panel which can shift image data around, but this involves changing the wave's scaling, since there is no offset option for images. I could implement this in the future. Would you find shifting and scaling images useful?

    Hi Tony,

    I went now through your StackTraces code. I found it very useful and have modified (reinterpreted) it with some new functionality. I would like to put this into the next GraphTools update, but first I would like to hear your opinion. Does the new version still work well with your workflow and data? If you look at the code you will see that I have rewritten a lot of details. This is my way of translating the functionality so that I understand what is going on (this included renaming menu entries a bit... I couldn't really wrap my head around the word 'stack' for most of the options). Also, I want to keep Igor 6.3 compatibility as much as possible for now.

    The code is now useable with 2D waterfall plots and honors x-offsets as well as y-scaling (I don't have x-scaling awareness in yet, but this will hopefully not be a problem). Now it is also possible to scale all traces (set a multiplier) to the same value at the cursor position. I have taken out addOffsets(), since this is probably already covered with the panel (if you find this more convenient this tool could go back in, of course).

    I have added alternative functionality when ctrl / command is pressed:

    • 'y-Offset: Align Traces' will align to zero instead of the cursors y value
    • 'y-Scale: Match Traces' will scale to 1 instead of the cursors y value
    • 'y-Order Traces' will sort in descending order

    Please let me know if you have any comments or suggestions for improvements. 

    newStackTraces.zip

    @Tony: I went ahead and merged the right-click menus into the project. I hope you like it. :)

    I do like it!

    The thing I still look for in the panel is 'shift offset per trace', the equivalent to the equivalent of my 'add offsets per trace' graph menu.

    Something that will add an additional offset of value*i to each trace. Is there a way to do that? Perhaps I'm missing something.

    Great! Let me know if I should add something else.

    The 'add offsets per trace' functionality is implemented in the panel as 'Set Offset per Trace' in the top right corner for both x and y directions. Just dial in a number or user the up/down arrows. This will add the inserted number as value*i to the traces. Also, 'Shift Offset of All Traces' will add the same offset to all traces, i.e., shift the whole bunch.

    I was trying to add rather than set the offsets. So the result is current offset + i*value.

    The idea is to able to quickly 'align' the traces by setting variable offsets, then add something to each offset to spread the traces apart from one another, with the possibility of adding or subtracting a bit more to spread them further or closer to one another.

    It looks like 'set offset per trace' discards the current offsets, ie it does what it says!

    Ah I see! Yes, the initial offsets and any alignment are not preserved. It should be no problem and make no difference for me to convert this into an add offset function. I'll think about it.

    Here is a version where I have added checkboxes to toggle between Set (the current behavior) and Add modes (this should recreate the 'add offsets per trace'). :) Let me know how well this works for you. If everything is fine then I will submit an update after doing a few more tests tomorrow.

    As a somewhat related side note, you may be shocked to hear that I have opened the All Traces Popup menu for the first time today. One learns something new every day. ;-p

    Graph Tools_v1.21-dev.zip

    Forum

    Support

    Gallery

    Igor Pro 8

    Learn More

    Igor XOP Toolkit

    Learn More

    Igor NIDAQ Tools MX

    Learn More