origin contour用法

6.9.2 Contour Plots and Color Mapping

Contour-Color-Map

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/Heat Map: 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. 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.
  2. 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.
    Tutorial81SetLevelsSetting.png
  3. 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.
    Tutorial81LoadPaletteOnPlotDetails.png
  4. 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.
  5. 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.
    Tutorial81CustomizedContour 1.png
  6. click OK. The contour should resemble the following image:
    Tutorial81CustomizedContour.png
  7. 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.
    Tutorial81ChangeWidthOfContour.png
    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.

    Tutorial81AddContoursNew.png
  8. 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:
    Tutorial81ExtractContourData.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. 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 ImportSingleASCII.png.
  2. Highlight the third column and right click on it to select Set As: Z. Select Plot: Contour/Heat Map: 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. 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 ImportSingleASCII.png.
  2. Highlight the third column and right click on it to select Set As: Z. Select Plot: Contour/Heat Map: Color Fill to create a graph.
    Tutorial81NewContourGraph.png
  3. 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:
    1210
    1812
    1618
    1416
  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.
    Tutorial81ContourCustomizeBoundary.png

    The graph should resemble the following image:

    Tutorial81ContourCustomizeBoundaryPlot.png
### 回答1: contour函数是MATLAB中的一个绘图函数,用于绘制等高线图。它的基本语法为: contour(Z) 其中,Z是一个二维矩阵,表示要绘制等高线图的数据。contour函数会根据Z中的数值自动确定等高线的数量和位置,并将其绘制出来。 除了基本语法外,contour函数还有一些可选参数,可以用来控制等高线图的绘制效果,例如: - contour(Z,levels):指定等高线的数量和位置,levels是一个向量,表示等高线的数值。 - contour(Z,v):指定等高线的数值,v是一个向量,表示等高线的数值。 - contour(Z,linespec):指定等高线的线型和颜色,linespec是一个字符串,可以包含线型、颜色和标记等信息。 - contour(Z,'fill'):绘制填充等高线图。 - contour(Z,'LineColor',color):指定等高线的颜色。 - contour(Z,'LineWidth',width):指定等高线的线宽。 总之,contour函数是一个非常实用的绘图函数,可以用来绘制各种类型的等高线图,例如地形图、气象图等。 ### 回答2: contour函数是Matlab中用于绘制等高线图的函数之一,其使用方法如下: 语法:contour (X, Y, Z, V) 其中X和Y分别为行向量和列向量,用于表示等高线图中x和y轴的坐标值。Z为一个矩阵,包含了等高线图中每个点的高度值。V是一个向量,用于指定需要画出哪几个等高线,例如V=[0 5 10 15],则只会画出高度为0、5、10和15的等高线。 调用contour函数后,Matlab会自动计算各个等高线的轮廓,并将其绘制在图形窗口中。用户也可以使用其他参数来调整等高线图的属性,例如: [...] = contour(..., <LineSpec>) LineSpec是一个字符串,用于指定等高线的颜色、线型、线宽等属性。例如'b-'表示蓝色实线;'r--'表示红色虚线;'g:'表示绿色点线等。用户还可以使用各种Matlab生成的参数,如LineWidth、LineStyle和Color等来设置等高线的属性。 [...] = contour(..., 'ShowText', <value>) 该参数用于指定是否在等高线上显示高度值。默认值为'off',如果将其设置为'on',则在等高线上会有高度值标注出现。 contour函数还有其他一些参数,如'Fill','LineWidth', 'LineColor'等,用户可以根据需要进行自由调整。 总之,通过contour函数,用户可以轻松绘制出等高线图,并对等高线图的属性进行自由调整。这为科学研究、图形分析等提供了极大的便利性。 ### 回答3: MATLAB 中的 contour 函数可以用于绘制三维数据的等高线图,也被称为轮廓线图。这种图形展示了曲面的高度和形状。MATLAB 中的 contour 函数用法如下: contour(Z):绘制矩阵 Z 的等高线图。Z 可以是一个二维矩阵,或两个二维矩阵 X 和 Y,其中 [X, Y] = meshgrid(x, y),x 和 y 是用于生成矩阵 Z 的向量,二维矩阵 X 和 Y 表示 x 和 y 的网格。 contour(Z, v):绘制具有特定高度的等高线,其中 v 是一个包含高度值的向量。 contour(Z, n):绘制 n 条等高线或与其大致相等的等高线。默认情况下,n=10。 contour(Z, v, 'LineColor', c):将等高线线条颜色设置为 c。 contour(Z, v, 'LineStyle', linetype):将线条样式设置为 linetype。 contour(Z, v, 'Fill', 'on'):以填充方式显示等高线图,填充颜色会根据每个区域的高度差异而变化。 contour(Z, v, 'TextStep', n):在绘制每 n 条等高线时标记数字。 除此之外,还可以通过设置等高线标签的属性、标题、坐标轴等来进一步优化所绘制的等高线图。总的来说,MATLAB 中的 contour 函数用法非常灵活,可用于各种数据可视化场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值