Sort print data in mplot3d

I use mplot3d (part of matplotlib) for some 3D plots and it does a great job. However, I ran into a new problem.

Mplot3d expects data to be sorted in a certain way to build a wireframe. For example, he likes something like this:

x = array([[1, 2, 3],
          [1, 2, 3],
          [1, 2, 3]])

y = array([[1, 1, 1],
          [2, 2, 2],
          [3, 3, 3])

where z is an array of the same sizes, with data corresponding to each of these positions in space.

Unfortunately, my data is not formatted like this: every other line is reversed, because the data is collected by scanning in a raster template.

So I have something more:

x = array([[1, 2, 3],
          [3, 2, 1],
          [1, 2, 3]])

- , , for, , , , , . , Z , X Y, , , , .

, , - 2- , , , , . , , , .

+3
1

, : x[1::2, :] = x[1::2, ::-1].

... x, , - , numpy.

, :

import numpy as np
x = np.array([[1,2,3],[3,2,1],[1,2,3],[3,2,1],[1,2,3]])
x_rev = x.copy()
x_rev[1::2, :] = x[1::2, ::-1]

(x):

array([[1, 2, 3],
       [3, 2, 1],
       [1, 2, 3],
       [3, 2, 1],
       [1, 2, 3]])

(x_rev):

array([[1, 2, 3],
       [1, 2, 3],
       [1, 2, 3],
       [1, 2, 3],
       [1, 2, 3]])

​​python, x[1::2] x, . (1 , 2 ). , x[::-1] -1, . , , .

+2

Source: https://habr.com/ru/post/1775740/


All Articles