How to plot array values against one axis with numpy in python ?


An example of how to create a scatter plot using array values versus one axis with numpy in python:

Create a simple array called A:

import numpy as np

A = np.array([[1, 2.2, 3.3, 3.6, 5.1],
              [1.2, 2.3, 3.4, 4.1, 5.5],
              [0.8, 1.7, 3.1, 4.2, 5.6],
              [1.1, 2.4, 3.5, 4.5, 5.2],
              [1, 2, 3, 4, 5]])

xx, yy = np.meshgrid(np.arange(A.shape[1]),np.arange(A.shape[0]))

print(xx)

returns

[[0 1 2 3 4]
 [0 1 2 3 4]
 [0 1 2 3 4]
 [0 1 2 3 4]
 [0 1 2 3 4]]

Plot with matplotlib:

plt.scatter(xx.ravel(),A.ravel())

plt.ylabel('Array Values')
plt.xlabel('Axis 1 Indices')

plt.savefig("array_values_vs_indices.png", bbox_inches='tight', dpi=100)

plt.show()

How to plot array values against one axis with numpy in python  ?
How to plot array values against one axis with numpy in python ?

Image

of