Plotting Mathematical Functions in Origin with Python Integration

Overview

Origin is a powerful tool for scientific graphing, but its built-in function plotting capabilities can be limiting when dealing with complex mathematical expressions or specific negative ranges. While the standard "2D Functon Plot" template works for simple equations, it often struggles with user-defined complex functions, such as neural network activation functions. Similarly, using the "Set Column Values" feature with row indices (e.g., Row(i)) is cumbersome for generating symmetric or negative domains.

A more efficient workflow involves using a Python environment, such as Spyder, to generate high-precision data points. These points can then be imported into Origin to leverage its advanced formatting and presentation features. This article outlines this hybrid approach using the Hard-sigmoid activation function as an example.

Generating Data with Python

Using Python allows for precise control over the domain and resolution of the data. We will use the numpy library to generate the X and Y values for the Hard-sigmoid function. This function linearly scales the input and clips the result between 0 and 1.

The following code snippet demonstrates how to generate the data:

import numpy as np

def compute_hard_sigmoid(input_data):
    """
    Applies the Hard-sigmoid activation function.
    Formula: clip((x + 1) / 2, min=0, max=1)
    """
    scaled_data = (input_data + 1.0) / 2.0
    # Restrict output values to the range [0, 1]
    return np.clip(scaled_data, 0.0, 1.0)

# Create a linear space of 200 points between -5 and 5
x_coordinates = np.linspace(-5, 5, 200)
y_coordinates = compute_hard_sigmoid(x_coordinates)

After executing the script in Spyder, the variables x_coordinates and y_coordinates will appear in the Variable Explorer.

Importing Data into Origin

To transfer the data into Origin:

  1. In Spyder's Variable Explorer, double-click x_coordinates to view the array.
  2. Select all value (Ctrl+A) and copy them (Ctrl+C).
  3. Open Origin and navigate to the worksheet. Paste the values into the first column (A(X)).
  4. Repeat the process for y_coordinates, pasting the data into the second column (B(Y)).

Once both columns are populated, highlight them and create a Line plot via the "Plot" menu or the toolbar shortcut.

Refining the Graph in Origin

Adjusting Axis Position

To improve the visual integrity, the axes should intersect at the zero point rather than the graph borders.

  • Method 1: Double-click the Y-axis to open the dialog. Navigate to the "Scale" tab (or "Axis Lines and Ticks" depending on the version). Look for the "Vertical" or "Axis Position" settings. Set the position to "At Value = 0".
  • Method 2: Manually select the axis and drag it to the X=0 position. Use the arrow keys for fine-tuning after zooming in.

Modifying Axis Scale and Range

Ensure the graph focuses on the relevant data. For instance, the Hard-sigmoid output is strictly between 0 and 1. To prevent the Y-axis from showing negative values:

  1. Double-click the Y-axis to open the Axis Dialog.
  2. Under the "Scale" tab, change the "From" value to 0 and adjust the "To" value as needed (e.g., 1.2).

Styling the Plot Line

Double-click the plot line to access the "Line" tab. Here you can adjust properties such as color (e.g., blue), width (e.g., 3 points), and connect type to suit the aesthetic requirements of a report or paper.

Labeling Axes

By default, columns are labeled A and B. To rename them:

  1. Double-click the text label on the axis.
  2. Replace "A" with "X" and "B" with "Y".
  3. Ensure font size and orientation are consistent.

Adding Grid Lines

Grid lines improve readability. To add them:

  1. Open the Axis Dialog for the Y-axis.
  2. Go to the "Grids" tab.
  3. Check the boxes for "Major Grids" and "Minor Grids".
  4. Set the Major Grid style to "Solid" or "Dot" and the Minor Grid to a lighter style.
  5. Repeat for the X-axis (Horizontal setting).

Adding Arrows to Axes

To give the plot a mathematical appearance:

  1. Double-click the axis to open the format dialog.
  2. Go to the "Line and Ticks" tab.
  3. Select the "Arrow" section and check the box for "Show Arrow at End".
  4. Adjust the arrow length and width as desired.

Annotating with Equations

Adding mathematical formulas directly to the graph requires using an Object Linking and Embedding (OLE) editor, such as the formula editor provided by Microsoft Word or WPS.

  1. In Origin, go to the "Insert" menu and select "Object".
  2. Choose "WPS Formula 3.0" or "Microsoft Equation 3.0" from the list and click OK.
  3. A text box and an equation editor toolbar will apear. Construct the desired formula.
  4. Close the editor and position the equation on the graph.

To segment the graph visually (e.g., dividing the linear region from the saturation region), use the "Line Tool" from the drawing toolbar. Set the line style to dashed and color it red to distinguish it from the plot.

Posted on Fri, 02 Oct 2026 16:32:38 +0000 by seanrock