【 MATLAB 】Contour plot of matrix(矩阵的等高线图)

版权声明:本博客内容来自于个人学习过程中的总结,参考了互联网、数据手册、帮助文档、书本以及论文等上的内容,仅供学习交流使用,如有侵权,请联系,我会重写!转载请注明地址! https://blog.csdn.net/Reborn_Lee/article/details/84316735

Contour plot of matrix

矩阵的等高线图

等高线图显示矩阵Z的等值线。使用clabel标记轮廓线。

contour(Z) 绘制矩阵Z的等高线图,其中Z被解释为相对于x-y平面的高度。 Z必须至少是包含至少两个不同值的2乘2的矩阵。 x值对应于Z的列索引,y值对应于Z的行索引。自动选择轮廓级别。

contour(Z,n) 绘制具有n个轮廓水平的矩阵Z的等高线图,其中n是标量。 自动选择轮廓水平。

contour(Z,v) 绘制矩阵Z的等高线图,轮廓线位于单调增加矢量v中指定的数据值。要在特定值处显示单个轮廓线,请将v定义为具有两个元素的双元素矢量 等于所需的轮廓水平。 例如,要在级别k绘制轮廓线,请使用轮廓(Z,[k k])。 指定向量v会将LevelListMode属性设置为手动。

contour(X,Y,Z)contour(X,Y,Z,n), and contour(X,Y,Z,v) draw contour plots of Z using X and Y to determine the x and y values.

  • If X and Y are vectors, then length(X) must equal size(Z,2) and length(Y) must equal size(Z,1). The vectors must be strictly increasing or strictly decreasing and cannot contain any repeated values.

  • If X and Y are matrices, then their sizes must equal the size of Z. Typically, you should set X and Y so that the columns are strictly increasing or strictly decreasing and the rows are uniform (or the rows are strictly increasing or strictly decreasing and the columns are uniform).

If X or Y is irregularly spaced, then contour calculates contours using a regularly spaced contour grid, and then transforms the data to X or Y.

如果 X 和 Y 是向量,则 length(X) 必须等于 size(Z,2),也即是Z的列数,length(Y) 必须等于 size(Z,1),也即是Z的行数。 向量必须严格增加或严格减少,并且不能包含任何重复值。

contour(...,LineSpec)使用LineSpec指定的线型和颜色绘制轮廓。 轮廓忽略标记符号。

contour(...,Name,Value) 使用一个或多个属性名称,属性值对指定轮廓属性。 Name是属性名称,必须出现在单引号('')中。 值是相应的值。 例如,'LineWidth',2将轮廓线宽设置为2.有关轮廓属性名称和值的列表,请参见轮廓属性。

contour(ax,...) 绘制到由ax指定的轴而不是当前轴(gca)。

[C,h] = contour(...)返回包含定义轮廓线的数据的轮廓矩阵C和Contour对象h。

Contour对象的ContourMatrix属性还包含轮廓矩阵。 clabel函数使用轮廓矩阵标记轮廓线。

使用“轮廓”对象属性可控制轮廓图外观。 有关列表,请参阅轮廓属性。


Create Contour Plot


Use the meshgrid function to generate matrices X and Y. Create a third matrix, Z, and plot its contours.
 

x = linspace(-2*pi,2*pi);
y = linspace(0,4*pi);
[X,Y] = meshgrid(x,y);
Z = sin(X)+cos(Y);

figure
contour(X,Y,Z)


Display Contour Labels

Set up matrices XY, and Z. Create a contour plot and display the contour labels by setting the ShowText property to on.

x = -2:0.2:2;
y = -2:0.2:3;
[X,Y] = meshgrid(x,y);
Z = X.*exp(-X.^2-Y.^2);

figure
contour(X,Y,Z,'ShowText','on')

Display Single Contour Line

Create a contour plot of the peaks function and display only one contour level at Z = 1.

x = -3:0.125:3;
y = -3:0.125:3;
[X,Y] = meshgrid(x,y);
Z = peaks(X,Y);
v = [1,1];

figure
contour(X,Y,Z,v)



Contour Properties

Contour chart appearance and behavior

Contour properties control the appearance and behavior of Contour objects. By changing property values, you can modify certain aspects of the contour chart.

轮廓属性控制Contour对象的外观和行为。 通过更改属性值,您可以修改等高线图的某些方面。

Starting in R2014b, you can use dot notation to query and set properties.

[C,h] = contour(...);
w = h.LineWidth;
h.LineWidth = 2;

If you are using an earlier release, use the get and set functions instead.


Color and Styling

Fill — Fill between contour lines
'off' (default) | 'on'

Fill between contour lines, specified as one of these values:

  • 'off' — Do not fill the spaces between contour lines with a color. This is the default value when you create the contour chart using the contour or contour3 functions.

  • 'on' — Fill the spaces between contour lines with color. This is the default value when you create the contour chart using the contourf function.

LineColor — Color of contour lines
'flat' (default) | RGB triplet | 'r' | 'g' | 'b' | ...

Color of contour lines, specified as 'flat', an RGB triplet, or one of the color options listed in the table.

  • To use a different color for each contour line, specify 'flat'. The colors are determined by the contour value of the line, the colormap, and the scaling of data values into the colormap. For more information on color scaling, see caxis.

  • To use the same color for all contour lines, specify an RGB triplet or one of the color options listed in the table.

For a custom color, specify an RGB triplet. An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1]; for example, [0.4 0.6 0.7]. Alternatively, you can specify some common colors by name. This table lists the long and short color name options and the equivalent RGB triplet values.

Option Description Equivalent RGB Triplet
'red' or 'r' Red [1 0 0]
'green' or 'g' Green [0 1 0]
'blue' or 'b' Blue [0 0 1]
'yellow' or 'y' Yellow [1 1 0]
'magenta' or 'm' Magenta [1 0 1]
'cyan' or 'c' Cyan [0 1 1]
'white' or 'w' White [1 1 1]
'black' or 'k' Black [0 0 0]
'none' No color Not applicable

LineStyle — Line style
'-' (default) | '--' | ':' | '-.' | 'none'

Line style, specified as one of the options listed in this table.

Line Style Description Resulting Line
'-' Solid line

'--' Dashed line

':' Dotted line

'-.' Dash-dotted line

'none' No line No line

ShowText — Contour line labels
'off' (default) | 'on'

Contour line labels, specified as one of these values:

  • 'off' — Do not label the contour lines.

  • 'on' — Display text labels on each contour line indicating the contour value.

猜你喜欢

转载自blog.csdn.net/Reborn_Lee/article/details/84316735
今日推荐