Questions about the input X of pcolor and contourf.

1 回表示 (過去 30 日間)
中祥 范
中祥 范 2024 年 7 月 19 日
編集済み: Cris LaPierre 2024 年 7 月 21 日
I have two questions, the first one is:
In the documentation of pcolor
the input arguments X is described as follows:
x-coordinates, specified as a matrix the same size as C, or as a vector of length n, where [m,n] = size(C). The default value of X is the vector (1:n).
To create a rectangular grid of vertices, specify X as either of the following:
  • A vector containing values that are increasing or decreasing.
  • A matrix that is increasing or decreasing along one dimension and is constant along the other dimension. Set the dimension that varies to the opposite of the dimension that varies in matrix Y. You can use the meshgrid function to create the X and Y matrices.
To create a parametric grid, create a rectangular grid and pass it through a mathematical function.
But in its case of specifying Parametric Grid, X and Y don't follow do not meet the above requirement, which is "A matrix that is increasing or decreasing along one dimension and is constant along the other dimension. Set the dimension that varies to the opposite of the dimension that varies in matrix Y."
I wonder if that means you can use X and Y coordinates for scatter points, for example:
X = [1 2 3; 2 3 4; 3 4 5]
Y = [1 1 1; 2 2 2; 3 3 3]
And the second one is:
In the documentation of contourf
x-coordinates, specified as a matrix the same size as Z, or as a vector with length n, where [m,n] = size(Z). The default value of X is the vector (1:n).
When X is a matrix, the values must be strictly increasing or decreasing along one dimension and remain constant along the other dimension. The dimension that varies must be the opposite of the dimension that varies in Y. You can use the meshgrid function to create X and Y matrices.
When X is a vector, the values must be strictly increasing or decreasing.
I wonder if that I can use X and Y coordinates for scatter points, for example:
X = [1 2 3; 2 3 4; 3 4 5]
Y = [1 1 1; 2 2 2; 3 3 3]

採用された回答

Cris LaPierre
Cris LaPierre 2024 年 7 月 19 日
移動済み: Cris LaPierre 2024 年 7 月 19 日
See this example: Specify parametric grid
[X,Y] = meshgrid(-3:6/17:3)
X = 18x18
-3.0000 -2.6471 -2.2941 -1.9412 -1.5882 -1.2353 -0.8824 -0.5294 -0.1765 0.1765 0.5294 0.8824 1.2353 1.5882 1.9412 2.2941 2.6471 3.0000 -3.0000 -2.6471 -2.2941 -1.9412 -1.5882 -1.2353 -0.8824 -0.5294 -0.1765 0.1765 0.5294 0.8824 1.2353 1.5882 1.9412 2.2941 2.6471 3.0000 -3.0000 -2.6471 -2.2941 -1.9412 -1.5882 -1.2353 -0.8824 -0.5294 -0.1765 0.1765 0.5294 0.8824 1.2353 1.5882 1.9412 2.2941 2.6471 3.0000 -3.0000 -2.6471 -2.2941 -1.9412 -1.5882 -1.2353 -0.8824 -0.5294 -0.1765 0.1765 0.5294 0.8824 1.2353 1.5882 1.9412 2.2941 2.6471 3.0000 -3.0000 -2.6471 -2.2941 -1.9412 -1.5882 -1.2353 -0.8824 -0.5294 -0.1765 0.1765 0.5294 0.8824 1.2353 1.5882 1.9412 2.2941 2.6471 3.0000 -3.0000 -2.6471 -2.2941 -1.9412 -1.5882 -1.2353 -0.8824 -0.5294 -0.1765 0.1765 0.5294 0.8824 1.2353 1.5882 1.9412 2.2941 2.6471 3.0000 -3.0000 -2.6471 -2.2941 -1.9412 -1.5882 -1.2353 -0.8824 -0.5294 -0.1765 0.1765 0.5294 0.8824 1.2353 1.5882 1.9412 2.2941 2.6471 3.0000 -3.0000 -2.6471 -2.2941 -1.9412 -1.5882 -1.2353 -0.8824 -0.5294 -0.1765 0.1765 0.5294 0.8824 1.2353 1.5882 1.9412 2.2941 2.6471 3.0000 -3.0000 -2.6471 -2.2941 -1.9412 -1.5882 -1.2353 -0.8824 -0.5294 -0.1765 0.1765 0.5294 0.8824 1.2353 1.5882 1.9412 2.2941 2.6471 3.0000 -3.0000 -2.6471 -2.2941 -1.9412 -1.5882 -1.2353 -0.8824 -0.5294 -0.1765 0.1765 0.5294 0.8824 1.2353 1.5882 1.9412 2.2941 2.6471 3.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Y = 18x18
-3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -3.0000 -2.6471 -2.6471 -2.6471 -2.6471 -2.6471 -2.6471 -2.6471 -2.6471 -2.6471 -2.6471 -2.6471 -2.6471 -2.6471 -2.6471 -2.6471 -2.6471 -2.6471 -2.6471 -2.2941 -2.2941 -2.2941 -2.2941 -2.2941 -2.2941 -2.2941 -2.2941 -2.2941 -2.2941 -2.2941 -2.2941 -2.2941 -2.2941 -2.2941 -2.2941 -2.2941 -2.2941 -1.9412 -1.9412 -1.9412 -1.9412 -1.9412 -1.9412 -1.9412 -1.9412 -1.9412 -1.9412 -1.9412 -1.9412 -1.9412 -1.9412 -1.9412 -1.9412 -1.9412 -1.9412 -1.5882 -1.5882 -1.5882 -1.5882 -1.5882 -1.5882 -1.5882 -1.5882 -1.5882 -1.5882 -1.5882 -1.5882 -1.5882 -1.5882 -1.5882 -1.5882 -1.5882 -1.5882 -1.2353 -1.2353 -1.2353 -1.2353 -1.2353 -1.2353 -1.2353 -1.2353 -1.2353 -1.2353 -1.2353 -1.2353 -1.2353 -1.2353 -1.2353 -1.2353 -1.2353 -1.2353 -0.8824 -0.8824 -0.8824 -0.8824 -0.8824 -0.8824 -0.8824 -0.8824 -0.8824 -0.8824 -0.8824 -0.8824 -0.8824 -0.8824 -0.8824 -0.8824 -0.8824 -0.8824 -0.5294 -0.5294 -0.5294 -0.5294 -0.5294 -0.5294 -0.5294 -0.5294 -0.5294 -0.5294 -0.5294 -0.5294 -0.5294 -0.5294 -0.5294 -0.5294 -0.5294 -0.5294 -0.1765 -0.1765 -0.1765 -0.1765 -0.1765 -0.1765 -0.1765 -0.1765 -0.1765 -0.1765 -0.1765 -0.1765 -0.1765 -0.1765 -0.1765 -0.1765 -0.1765 -0.1765 0.1765 0.1765 0.1765 0.1765 0.1765 0.1765 0.1765 0.1765 0.1765 0.1765 0.1765 0.1765 0.1765 0.1765 0.1765 0.1765 0.1765 0.1765
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
XX = 2*X.*Y
XX = 18x18
18.0000 15.8824 13.7647 11.6471 9.5294 7.4118 5.2941 3.1765 1.0588 -1.0588 -3.1765 -5.2941 -7.4118 -9.5294 -11.6471 -13.7647 -15.8824 -18.0000 15.8824 14.0138 12.1453 10.2768 8.4083 6.5398 4.6713 2.8028 0.9343 -0.9343 -2.8028 -4.6713 -6.5398 -8.4083 -10.2768 -12.1453 -14.0138 -15.8824 13.7647 12.1453 10.5260 8.9066 7.2872 5.6678 4.0484 2.4291 0.8097 -0.8097 -2.4291 -4.0484 -5.6678 -7.2872 -8.9066 -10.5260 -12.1453 -13.7647 11.6471 10.2768 8.9066 7.5363 6.1661 4.7958 3.4256 2.0554 0.6851 -0.6851 -2.0554 -3.4256 -4.7958 -6.1661 -7.5363 -8.9066 -10.2768 -11.6471 9.5294 8.4083 7.2872 6.1661 5.0450 3.9239 2.8028 1.6817 0.5606 -0.5606 -1.6817 -2.8028 -3.9239 -5.0450 -6.1661 -7.2872 -8.4083 -9.5294 7.4118 6.5398 5.6678 4.7958 3.9239 3.0519 2.1799 1.3080 0.4360 -0.4360 -1.3080 -2.1799 -3.0519 -3.9239 -4.7958 -5.6678 -6.5398 -7.4118 5.2941 4.6713 4.0484 3.4256 2.8028 2.1799 1.5571 0.9343 0.3114 -0.3114 -0.9343 -1.5571 -2.1799 -2.8028 -3.4256 -4.0484 -4.6713 -5.2941 3.1765 2.8028 2.4291 2.0554 1.6817 1.3080 0.9343 0.5606 0.1869 -0.1869 -0.5606 -0.9343 -1.3080 -1.6817 -2.0554 -2.4291 -2.8028 -3.1765 1.0588 0.9343 0.8097 0.6851 0.5606 0.4360 0.3114 0.1869 0.0623 -0.0623 -0.1869 -0.3114 -0.4360 -0.5606 -0.6851 -0.8097 -0.9343 -1.0588 -1.0588 -0.9343 -0.8097 -0.6851 -0.5606 -0.4360 -0.3114 -0.1869 -0.0623 0.0623 0.1869 0.3114 0.4360 0.5606 0.6851 0.8097 0.9343 1.0588
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
YY = X.^2 - Y.^2
YY = 18x18
0 -1.9931 -3.7370 -5.2318 -6.4775 -7.4740 -8.2215 -8.7197 -8.9689 -8.9689 -8.7197 -8.2215 -7.4740 -6.4775 -5.2318 -3.7370 -1.9931 0 1.9931 0 -1.7439 -3.2388 -4.4844 -5.4810 -6.2284 -6.7266 -6.9758 -6.9758 -6.7266 -6.2284 -5.4810 -4.4844 -3.2388 -1.7439 0 1.9931 3.7370 1.7439 0 -1.4948 -2.7405 -3.7370 -4.4844 -4.9827 -5.2318 -5.2318 -4.9827 -4.4844 -3.7370 -2.7405 -1.4948 0 1.7439 3.7370 5.2318 3.2388 1.4948 0 -1.2457 -2.2422 -2.9896 -3.4879 -3.7370 -3.7370 -3.4879 -2.9896 -2.2422 -1.2457 0 1.4948 3.2388 5.2318 6.4775 4.4844 2.7405 1.2457 0 -0.9965 -1.7439 -2.2422 -2.4913 -2.4913 -2.2422 -1.7439 -0.9965 0 1.2457 2.7405 4.4844 6.4775 7.4740 5.4810 3.7370 2.2422 0.9965 0 -0.7474 -1.2457 -1.4948 -1.4948 -1.2457 -0.7474 0 0.9965 2.2422 3.7370 5.4810 7.4740 8.2215 6.2284 4.4844 2.9896 1.7439 0.7474 0 -0.4983 -0.7474 -0.7474 -0.4983 0 0.7474 1.7439 2.9896 4.4844 6.2284 8.2215 8.7197 6.7266 4.9827 3.4879 2.2422 1.2457 0.4983 0 -0.2491 -0.2491 0 0.4983 1.2457 2.2422 3.4879 4.9827 6.7266 8.7197 8.9689 6.9758 5.2318 3.7370 2.4913 1.4948 0.7474 0.2491 0 0 0.2491 0.7474 1.4948 2.4913 3.7370 5.2318 6.9758 8.9689 8.9689 6.9758 5.2318 3.7370 2.4913 1.4948 0.7474 0.2491 0 0 0.2491 0.7474 1.4948 2.4913 3.7370 5.2318 6.9758 8.9689
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
colorscale = [1:18; 18:-1:1];
C = repmat(colorscale,9,1);
pcolor(XX,YY,C);
  3 件のコメント
中祥 范
中祥 范 2024 年 7 月 21 日
So do you mean that we can use special data such as that in the Specify parametric grid case which does not meet the matrix requirements for X in pcolor and contourf ?
Cris LaPierre
Cris LaPierre 2024 年 7 月 21 日
編集済み: Cris LaPierre 2024 年 7 月 21 日
I have shared a couple examples of what parametric grids might be Based on that, I would interpret the doc as providing independent recommenations on how to create X and Y. There is the traditional grid, and then there is a parametric grid.
Feel free to try out some things on your own. That always helps me understand what is possible.

サインインしてコメントする。

その他の回答 (1 件)

Voss
Voss 2024 年 7 月 19 日
編集済み: Voss 2024 年 7 月 19 日
I interpret the pcolor documentation as saying that a rectangular grid and a parametric grid are separate special cases, so the X of a parametric grid does not have to conform to the requirements of the X of a rectangular grid.
In other words, the general requirement on X is:
"x-coordinates, specified as a matrix the same size as C, or as a vector of length n, where [m,n] = size(C). The default value of X is the vector (1:n)."
If you want a rectangular grid (a special case), then
"To create a rectangular grid of vertices, specify X as either of the following:
  • A vector containing values that are increasing or decreasing.
  • A matrix that is increasing or decreasing along one dimension and is constant along the other dimension. Set the dimension that varies to the opposite of the dimension that varies in matrix Y. You can use the meshgrid function to create the X and Y matrices."
If you want a parametric grid (another special case), then:
"To create a parametric grid, create a rectangular grid and pass it through a mathematical function."
So your example works fine:
X = [1 2 3; 2 3 4; 3 4 5];
Y = [1 1 1; 2 2 2; 3 3 3];
Z = rand(3);
pcolor(X,Y,Z)
The same example also works for contourf, even though it appears to violate the requirements specified in its documentation:
contourf(X,Y,Z)
In fact, you can use arbitrary matrices in either function without error (assuming their sizes are consistent with each other), but the outputs may be difficult to interpret:
X = rand(5,8);
Y = rand(5,8);
Z = rand(5,8);
pcolor(X,Y,Z)
contourf(X,Y,Z)

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by