6.9.2 Contour Plots and Color Mapping
Origin offers rectangular, polar, and ternary contour plots. For rectangular contour plots, the data can be either in a matrix or in a worksheet in XYZ format. Polar contour plots can be generated from three columns of data in a worksheet, organized either as R Z or R Z. Ternary contour plots can be generated from worksheet data organized in X Y Z Z format where the 2nd Z-column contains the 4th parameter which is the height value at a given XYZ point in the ternary space.
Many options are available for customizing contour plots, such as setting different major and minor contour levels, displaying contour lines only at major levels, applying color palettes, and also control for a custom boundary in the case of contour plots created directly from the worksheet.
What You Will Learn
This tutorial will show you how to:
- Set values in a Matrix and create a Contour Plot
- Customize levels, lines, and color mapping
- Extract data from contour lines
- Create a Contour Plot directly from XYZ data
- Use a Custom Boundary
Create Contour Plot from Matrix
- To create a new matrix click the New Matrix button . Move the cursor to the upper left corner of the matrix until the shape of the pointer changes as in the following image and click to select the entire matrix.
To set the dimensions, right-click and select Set Matrix Dimension/Labels in the context menu. On the XY Mapping tab, change setting as shown below .
- Input data into the matrix by highlighting it and right-clicking. Select Set Matrix Values in the context menu to open the Set Values dialog. Type i*sin(x) - j*cos(y) in the Formula edit box and click the OK button to generate data. The matrix should look like this:
- Each data point in the matrix corresponds to two different kinds of indices. One is the column and row indices. The other is the X and Y coordinates. Select View: Show X/Y from the main menu to see the X, Y coordinates:
- You can also select View: Image Mode to show the image form of the matrix:
- Select View: Data Mode to exit the image mode. Create a contour plot by activating the matrix and selecting Plot: Contour/Heatmap: Color Fill. The graph should appear as shown below:
Customize Levels, Lines and Color Map
Origin makes it easy to customize every aspect of the contour plot, including the color scale and adding labels:
- Double click on the contour plot to open the Plot Details dialog. Make sure the left panel is expanded by clicking on the arrow button on the bottom left of the dialog. Click on Layer1 in the left panel (leave the check-box checked, and click on the word itself), and select the Size/Speed tab in the right panel. Disable the Matrix data, maximum points per dimension box to turn off Speed Mode.
- Expand the Layer option in the left panel and select [MBook1]MSheet1!1(Z)(1:10201) under it to open the matrix level options. Select Colormap/Contours in the right panel and click on the Level heading to open the Set Levels dialog. Click the Find Min/Max button and set Major Levels to 8 and Minor Levels to 32. Click the OK button.
- Now load a palette for the contour. Click on the Fill heading. In the dialog that opens, select the Load Palette radio box. Click the Select Palette button and select the Rainbow palette from the drop-down. Click OK.
- Click the Line heading to open the Contour Lines dialog. Check the Show on Major Levels only box and click OK. Then click the OK button to close the Plot Details dialog.
- Set the properties for the color scale. Right click on the color scale and select Properties from the context menu to open the Color Scales Control dialog. Select Levels in left panel, select All Major Levels for the Show on drop-down list.
- click OK. The contour should resemble the following image:
- Click twice on a contour line (two separate single clicks) to select all lines at that level. Change the color to Green by using the Line/Border Color button in the Font toolbar. Change the width to 3 by using the Line/Border Width button in the same toolbar.
Make sure only one contour line is selected (not all the contour lines at that level) and right click on the selected contour line. Select Add Contour Label to add a label.
- Click twice on a contour line to select it, right click and select Extract Contour Lines. Origin will extract the data for that contour line to a worksheet. The following image shows part of the data in the worksheet:
Create a Contour Plot from XYZ Data
Origin can create contour plots directly from XYZ data in a worksheet without the need for an intermediate matrix. Delaunay Triangulation is used to compute and draw the contour lines.
- Create a new worksheet and import the 3D XYZ.dat from the \Samples\Matrix Conversion and Gridding folder by using the Import Single ASCII button .
- Highlight the third column and right click on it to select Set As: Z. Select Plot: Contour/Heatmap: Color Fill to create a graph as in the following image:
Show the Triangulation Grid
- Show the triangulation grid that is used to create a contour plot from the data. The individual data points are located at the nodes or vertices of the grid. Create a new worksheet and import the XYZ Random Gaussian.dat file from the \Samples\Matrix Conversion and Gridding folder by using the Import Single ASCII button .
- Highlight the third column and right click on it to select Set As: Z. Select Plot: Contour/Heatmap: Color Fill to create a graph.
- Double click on the contour plot to open the Plot Details dialog. On the Colormap/Contours tab, click on the Line heading to open the Contour Lines dialog. Deselect Shown on Major Levels Only and select Hide All to hide all the contour lines. Click OK to close this dialog. Then select the Show Grid Lines and Show Data Points check boxes. Click OK to close the Plot Details dialog.
The contour plot with its superimposed grid should look like this:
Apply Custom Boundary
A custom boundary can be applied to contour plots created directly from XYZ data where user provides the data points for the boundary in additional columns of the same worksheet. This feature is useful when there is a specific boundary data that defines the outline of an object, for example the profile of an engine where the contour shows engine temperature.
Continue to use the worksheet and the contour plot that was created with the XYZ Random Gaussian.dat in the previous example.
- In the XYZRandomGaus workbook, click the Add New Columns button twice to add two columns. Highlight the two columns and right click on them. Select Set As: XY XY from the context menu and enter four rows of data such as below:
- Double click on the contour plot to open the Plot Details dialog. Select the Contouring Info tab in the right panel. Set the dialog as in the following image to customize the boundary for the contour plot. Remember to uncheck the Show Grid Lines and Show Data Points check boxes in the Color Map/Contours tab. Click OK to close the Plot Details dialog.
The graph should resemble the following image:
Prior to Origin 2018 SR0, the application of a custom boundary sometimes generated an imperfect fill at boundary margins. This has been improved in 2018. The user can restore the previous contour-fill behavior using system variable @TCSM.