How to Plot 3D Boxes in Origin

This blog describes how to make 3D boxes like the following picture by a LabTalk function. (Click picture to enlarge.)

This graph sample was created by the following LabTalk code, which contains four functions – plot3DBox to make a single 3D box and its subroutines plotOneSide and cleanMatData, and the main function make3DBoxes to create multiple boxes specified in a worksheet (Book1 in above sample). You can run the program by simply issuing make3DBoxes command in the Script window,




To Run this Script to make 3D Boxes from a worksheet data, you can follow the four steps below:

1) Using Notepad, save this script code as a script file, make3DBoxes.OGS in your User Files Folder(UFF).
Or, you can download the ZIP file of the code from here , and put the content “make3DBoxes.OGS” in the ZIP file into your UFF.
(To open your UFF location, choose “Help: Open Folder: User Files Folder” menu in Origin.)

2) For startup loading of the global functions, find Origin.INI file in your UFF, open it by Notepad, find “[Startup]” section, insert the following line just under this section line (where # is a number like 1, 2, 3,…):
and save it. Now you are ready to run “make3DBoxes” command any time available in Origin as described in the following steps. (See the details of these two steps here.)

3) Start Origin (your global functions will be automatically loaded), create a worksheet with 9 columns, and enter the data of your boxes. Each row of the worksheet specifies a box’s corner position, dimensions, and the colors. (See the sample worksheet in the above screenshot.) The columns contain the following data:
Column 1/2/3 : the base coordinates, X/Y/Z coordinates
Column 4/5/6 : Dimensions of the 3D box in X/Y/Z directions
Column 7/8/9 : Face pair colors of Right+Left/Front+Back/Top+Bottom. (1=Black, 2=Red, 3=Green, 4=Blue,… etc. See the whole color list.)

4) Set the worksheet active, and issue the following command in the Command window or in Script window:
Origin now draws 3D boxes specified in the worksheet, in a graph window.

If you want to draw a 3D box  in an existing 3D graph such as with a 3D scatter plot, you can issue a command like the following:

Finally, note that you can customize this sample code for your needs such as for specifying subtle colors using RGB values (using color() function), specifying six distinct colors for all faces (by increasing the number of color arguments), drawing edge lines (by overlaying 3D line plots), etc.



1: Currently LabTalk lacks the capability to control the transparency of the surface. OriginLab is working to implement this feature, and once it is done, I will update the above sample code.

2: This script code was modified from the sample code in this help page. In this sample code, you can find a sample function to draw a sphere.

3: You can also make a function to create a rectangle (similar to plotOneSide in this blog’s sample) by creating two triangles as a “triangle patch” from a worksheet which contains 4 columns; the first three for corner XYZ coordinates, and the fourth for the route of the corner connections. After creating the worksheet, you can create a Color Fill 3D Surface plot, then execute “Set -spi ” command like the following pseudo code:


Leave a Reply

Your email address will not be published. Required fields are marked *