This is an archived page, please click here to view the latest updates.

OriginLab Corporation - Scientific Graphing and Data Analysis Software - 2D graphs, 3D graphs, Contour Plots, Statistical Charts, Data Exploration, Statistics, Curve Fitting, Signal Processing, and Peak Analysis

Creating Contour Graphs

Image:Video_Image.png See more related video:Contour Plots and Color Mapping

Contour graphs are surface graphs of XYZ data, plotted in 2D space. Viewing a contour graph is the same as viewing a 3D surface graph from a vantage point perpendicular to the XZ plane. In contour graphs, ranges of Z values are distinguished by different colors or levels of gray scale, labeled contour lines, or both.

Image:A Note about Contour Graphs-01.png

Contents

Contour Graph Types

Origin provides six contour graph types:

Graph Type XYZ Columns in Worksheet Matrix Window Virtual Matrix in Worksheet
  • Countour-Color Fill
  • Contour - B/W Lines+Labels
  • Gray Scale Map
Yes Yes Yes
  • Poloar Contour thea(x)r(y)
  • Poloar Contour r(x)thea(y)
  • Ternary Contour
Yes No No

The (Plot Details) Color Map/Contours, Label, and Numeric Formats tabs provide controls for editing your contour graphs.

Note that a contour plot in Origin can be created from matrix data, worksheet data, or virtual matrix data. Creating a contour plot from a matrix is faster than creating a contour plot directly from a worksheet, so the matrix method is suitable for large data. On the other hand, creating a contour plot directly from XYZ worksheet data uses a triangulation method to generate the contour lines, and there is no need to generate a matrix. Besides that, there are other advantages to creating contour graphs from XYZ worksheets:

  1. Supports both Cartesian Coordinates and Cylindrical Coordinates.
    Image:A Note about Contour Graphs-02.png
  2. Supports Layer Boundary, Data Boundary and Custom Boundary.
    Image:A Note about Contour Graphs-03.png
  3. Supports Ternary Contour Plots
    Image:Contour_Graphs_10.png

Compared to creating contour graphs from a matrix, creating graphs from a virtual matrix can let the graphs have nonlinear X/Y axes.

How to Create and Customize Contour Graphs

To create a Contour graph from matrix data or worksheet data, you just need to select the data, and click the graph button on the 3D and Contour Graphs toolbar or select a graph menu option under the main Plot menu. To create a graph from a virtual matrix, you can only click the graph button on the 3D and Contour Graphs toolbar to bring up a dialog to help you set the XYZ data and then create the graph. For more details about creating graphs from virtual matrices, please refer to Creating 3D and Contour Graphs from Virtual Matrix. We have also introduced each Contour graph type, in detail, in Contour Graphs; you can get more details from there.

The customizations of Contour graphs are mainly done in the Axis dialog and the Plot Details dialog; you can get more details about the Axis dialog to learn how to customize the axes of a graph from Graph Axes. To get more details about the Plot Details dialog, please refer to Customizing Your Graph.

The Highlight Features for Contour Graphs

There are some very useful and important features, only available with contour graphs, with which you can make your graphs unique and beautiful.

Adding/Removing Contour Labels and Extracting Contour Lines

In addition to controlling contour labels in the Color Map/Contours tab of the Plot Details dialog, you can manually add contour labels for a selected contour line. To do this:

  1. Click on the contour line thrice to select it.
  2. Right-click and select Add Contour Label from the short-cut menu.
Image:A_Note_about_Contour_Graphs-09.png

Note that this command is accessible only when you have selected a single contour line.

After adding the label, you can use the Remove Contour Label(s) command to remove it. When you click a contour line twice to select all the lines with the same z value, you can right-click to choose this command from the context menu and remove all the labels added to this level. When clicking a third time to select a single contour line, you can use this command to remove the label associated with this line.

The context menu that appears when you right-click on a selected contour line offers another menu command: Extract Contour Lines. This menu command can be used to extract the data of the selected contour line to a new workbook. When you right-click in the contour plot, rather than on a contour line, the Extract Contour Lines option that appears in the context menu will extract the data of all showing contour lines to a new workbook.

Algorithm for Creating a Contour from a Worksheet

Contour plots can be created directly (without gridding) from (x, y, z) coordinates (Cartesian coordinates) or (r, θ, z) coordinates (cylindrical coordinates). If your data are in (r, θ, z) coordinates, Origin first converts the data to XYZ space before making the contour plot. Conversions between (x, y, z) and (r, θ, z) coordinates are expressed as:

r=\sqrt{x^2+y^2}

\theta =\tan ^{-1}\left( \frac yx\right)

z=z\,\!

and...

x=r\cos\theta \,\!

y=r\sin\theta\,\!

z=z\,\!

Image:A Note about Contour Graphs-04.png

In Cartesian space, creating a contour plot is a four step process:

Triangulation

All data points are connected to create Thiessen (Delaunay) triangles in the XY plane. The triangles are constructed so as to make them as equiangular as possible. In addition, no two triangles should intersect. Note that any side is shared by two adjacent triangles, unless it is located at the edge of the mesh.

Image:A Note about Contour Graphs-05.png

Linear interpolation

To find the intersection points of the contour lines and the triangle sides:

Given a contour level zc, Origin traverses all the triangles to see whether or not the contour line for this level intersects with the triangle sides. If a triangle side has intersection with the contour line, it will be marked as a characteristic side. The coordinates of the intersection point, which will be referred to as a characteristic point in this document, will be computed with linear interpolation.

For a triangle side that connects two triangle vertices: I(xi, yi, zi) and J(xj, yj, zj), we will examine whether the following is true:

\left( z_i-z_c\right) *\left( z_j-z_c\right) <0

z_i=z_i-\varepsilon

z_j=z_j-\varepsilon

If it is true, we will say that this side is a characteristic side. Furthermore, if the product on the left of the inequality is zero, it will mean that the contour line passes through at least one of the vertices. In this case, zi and zj will be adjusted by subtracting a small value, \varepsilon, so as to make sure that the characteristic point will not be a vertex. The adjustment is as follows:

where \varepsilon = 1e^{-15}.

Image:A Note about Contour Graphs-06.png

If this side is a characteristic side, the coordinates of the characteristic point on it can be computed by linear interpolation in the following way:

x_c=x_i+\frac{x_j-x_i}{z_j-z_i}\left( z_c-z_i\right)

y_c=y_i+\frac{y_j-y_i}{z_j-z_i}\left( z_c-z_i\right)

Origin keeps records of all the characteristic sides and the coordinates of the characteristic points for future use.

Note that if a triangle intercepts the contour line, it will have exactly two characteristic sides.

Drawing of contour lines

To draw a contour line, we have to trace all the characteristic points on it.

If there is a characteristic point on the boundary of the triangular mesh, the tracing will start from that point. Otherwise, the tracing will begin with a random characteristic point.

Recall that a triangle that intercepts the contour line must have exactly two characteristic sides, and that a side which is not on the edge of the mesh must be shared by two triangles. Therefore, the tracing can go from one characteristic side (Side A in the following figure) to the other characteristic side of the same triangle (Side B in the following figure). If the latter is not on the edge of the triangular mesh, we will certainly find another triangle (Triangle 2 in the following figure) which shares this side with the current triangle (Triangle 1 in the following figure). Then we can find the characteristic point on the other characteristic side (Side C in the following figure) of this new triangle. In this way, the tracing continues until the edge of the mesh or a characteristic point which has already been traced is reached. (In the former case, the contour line is open; while in the latter case, it is closed.) Then the number of characteristic points that have been traced is compared with the total number of characteristic points for this level. If they are not equal, it will mean that there are still some characteristic points which have not been traced. The tracing will go on until all characteristic points have been traced.

Image:A Note about Contour Graphs-07.png

Connecting and smoothing

After the tracing, the characteristic points are connected with B-Spline curves. Then smoothing is performed on all the contour curves.

Image:A Note about Contour Graphs-08.png

Reference:

  1. Robert J. Renka. Interpolation of Data on the Surface of a Sphere. ACM Transactions on Mathematical Software, Vol. 10, No. 4, December 1984, Pages 417-436.
  2. Fen Yuan, Automatic Drawing of Equal Quantity Curve. Computer Aided Engineering, No. 3 Sept. 1998.