In this tutorial, we will learn how to display numpy array using pyplot from mat plot library, Matplotlib is another open source library in python that allow us to create graphical representation of any data, here we see how to display numpy array in form of image using pyplot. learn more about Python Matplotlib library
There are two important libraries from data visualization from Matplotlib, they are pyplot and image.
import matplotlib.pyplot as plt import matplotlib.image as mpimg
Here first we learn how to use pyplot to display numpy array information, then we look how to import image inside chart and display with array data.
import numpy as np from matplotlib import pyplot as plt x = np.arange(1,10) y = np.arange(11,20) plt.title("Numpy Array with pyplot") plt.xlabel("x axis caption") plt.ylabel("y axis caption") plt.plot(x,y) plt.show()
In above code we have created two one-dimension array and then called plot method like
Here is the output
Now we see how to display multiple one-dimension arrays in one chart, you can think of three products details displayed for comparison.
Here we define three one-dimension array and then add each array to bar property using
plt.bar(x, y, align = 'center')
import numpy as np from matplotlib import pyplot as plt x = [3,12,9,11] y = [13,17,6,18] plt.bar(x, y, color = 'g', align = 'center') x2 = [13,9,11,14] y2 = [4,15,8,16] plt.bar(x2, y2, color = 'r', align = 'center') x3 = [9,11,8,19] y3 = [7,14,6,17] plt.bar(x3, y3, color = 'b', align = 'center') plt.title('multicolor bar graph: WebTrainingRoom') plt.ylabel('Y axis') plt.xlabel('X axis') plt.show()