How can I plot a 2D line from a chosen axis of a Numpy Array quickly?
An analogy: when sum an arbitrary matrix sigma with respect to axis = 0, I would write:
import numpy as np
import matplotlib.pyplot as plt
sigma = np.array([
[[0. , 0.9, 0.6],
[0. , 0. , 0.4],
[0. , 0. , 0. ]],
[[0. , 0.8, 0.5],
[0. , 0. , 0.3],
[0. , 0. , 0. ]],
[[0. , 0.7, 0.4],
[0. , 0. , 0.2],
[0. , 0. , 0. ]]
])
np.sum(sigma, axis=0)
with result:
array([[0. , 2.4, 1.5],
[0. , 0. , 0.9],
[0. , 0. , 0. ]])
I am seeking an equivalent straight forward method to plot axis=0, suggestively similar to:
plt.plot(sigma, axis=0)
This means, I will plot the depth of the matrix at each corresponding position. In the plot I will see three lines, one line starting at 0.9 in value at x =1, and 0.8 at x=2, and 0.7 at x-3. Similarly, for lines two and three, [0.6, 0.5, 0.4] ; [0.4, 0.3, 0.2].
I could find examples of plot 3d and a method (involving slice and len) for plot 2d that would yield in a solution similar to:
plt.plot(sigma[:,:,2])
However, I cannot get it to plot against the x-axis (x = 1..3, representing each layer of array)
How do I do it?
Update: a solutions seems to be:
plt.plot(sigma[:,:,:].reshape((3, 9)))
