Word interpretation numpy.meshgrid () - matrix generating grid point coordinates.
Keywords: grid point coordinate matrix
What grid point? Coordinate matrix is what the hell?
Look at a map to understand:
Drawing, each intersection of the grid points is described matrix coordinates of these grid points, that is, the coordinates of the matrix.
Look at a simple example
A, B, C, D, E, F six grid points, as shown in FIG coordinates, how to use a matrix form (matrix coordinates) to describe these coordinate points in bulk of it?
Below you can own matplotlib to try, the output is on top of the chart
If not familiar matplotlib, may only know the abscissa using a (1-dimensional column vector linear algebra), to generate an ordinate (the number of both elements are equal) at some point. But in fact, to the coordinate information matplotlib matrix is also possible, as long as the horizontal and vertical dimensions of the same coordinates. Points are generated in a corresponding relationship.
But there needs attention, as the same line in accordance with the dot matrix corresponding to the coordinate point information, matplotlib will abscissa matrix, each column.
For example, the above code plot of linestyle = '' delete, or become lineStyle = '-' (the operation of the linear to FIG default state), will find AD is connected, BE is connected a, CF is connected, i.e., you will think you are three input lines, FIG.
As an exercise, try for yourself produces the following results
Tip: linear and other key parameters are available the following code
answer
Here, the concept of the grid points and the coordinates of the matrix to explain.
So the question is, if desired picture is relatively large, requires a lot of grid points how to do it? For example, following this
But the most direct and the most stupid way is to follow the above method to horizontal and vertical coordinates matrix X XX, Y YY written, as in the above exercises
Clearly, for many grid points situation simply can not use. So what better way to do?
Yes, we note that in practice the coordinate matrix questions, in fact, a large number of duplicate --X XX of each row as each column Y YY are the same. Based on this strong regularity, numpy provided numpy.meshgrid () function allows us to quickly generate coordinate matrix X, Y.
Syntax: X, Y = numpy.meshgrid (x , y)
horizontal and vertical coordinates of the input column vector x, y, is the grid points (non-matrix)
outputs X, Y, is the coordinate matrix.
Let's try it: rewrite the code for the first example of using numpy.meshgrid to achieve.
Finally, the above code of FIG.
----------------
Disclaimer: This article is the original article CSDN bloggers "thousands Sama", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source and link this statement.
Original link: https: //blog.csdn.net/lllxxq141592654/article/details/81532855