6.8.2 Contour Plots and Color Mapping


Video Image.png Video Text Image.png Website blog icon circle.png Blog Image 33x33px.png

Summary

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 \Theta Z or \Theta 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

  1. To create a new matrix click the New Matrix button CreateNewMatrix.png. 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.
    SelectWholeMatrix.png
    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 .
    SetDimension.png
  2. 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:
    ShowRowColumnIndex.png
  3. 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:
    ShowXYCoordinatesNew.png
  4. You can also select View: Image Mode to show the image form of the matrix:
    MatirxShowAsImage.png
  5. Select View: Data Mode to exit the image mode. Create a contour plot by activating the matrix and selecting Plot > Contour: Contour - Color Fill. The graph should appear as shown below:
    OriginalContourGraphNew.png

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:

  1. Active Graph1, and select Graph: Speed Mode menu to open the dialog. Set Speed Mode = Off and click OK"'
  2. Click on the Contour plot in Graph1, and then click on the Set Levels button on the pop-up Mini Toolbars. In 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.
    Contour Plots Mini Toolbar Set Levels.png
  3. Click on the Contour plot, and then click on the Palettes button on the pop-up Mini Toolbars. Then select the Rainbow palette from the drop-down.
    Contour Plots Mini Toolbar Palettes.png
  4. 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 Tutorial81LineAndBordColorGreen.png in the Font toolbar. Change the width to 3 by using the Line/Border Width button Tutorial81WidthNew.png in the same toolbar.
    Contour Plots Custom Contour Lines.png
  5. 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.
    Contour Plots Add Contour Label.png
  6. 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:
    Contour Plots Extract Contour Lines.png


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.

  1. Start with an empty worksheet. Select Help: Open Folder: Sample Folder... to open the "Samples" folder. In this folder, open the Matrix Conversion and Gridding subfolder and find the file 3D XYZ.dat. Drag-and-drop this file into the empty worksheet to import it.
  2. Highlight the third column and right click on it to select Set As: Z. SelectPlot > Contour: Contour - Color Fill to create a graph as in the following image:
    Tutorial81CreateXYZContour.png

Show the Triangulation Grid

  1. 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.
  2. Start with an empty worksheet. Select Help: Open Folder: Sample Folder... to open the "Samples" folder. In this folder, open the Matrix Conversion and Gridding subfolder and find the file XYZ Random Gaussian.dat. Drag-and-drop this file into the empty worksheet to import it.
  3. Highlight the third column and right click on it to select Set As: Z. SelectPlot > Contour: Contour - Color Fill to create a graph.
    Tutorial81NewContourGraph.png
  4. 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.
    Tutorial81ShowGrideLinesNew.png
    The contour plot with its superimposed grid should look like this:
    Tutorial81ContourShowGridLine.png

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.

  1. Continue to use the worksheet and the contour plot that was created with the XYZ Random Gaussian.dat in the previous example.
  2. In the XYZRandomGaus workbook, click the Add New Columns button Tutorial81AddColumns.png 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:
    12 10
    18 12
    16 18
    14 16
  3. 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.
  4. Tutorial81ContourCustomizeBoundary.png

    The graph should resemble the following image:

    Tutorial81ContourCustomizeBoundaryPlot.png

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.

Tri contour smooth mode.png