Skip to main content

Posts

Showing posts from May, 2019

Plotting with Matplotlib

Matplotlib is a Python library used for visualizing data. It is an extensive library and sub-modules like pyplot provides functionality equivalent to Matlab. Let's start by understanding few basic components :- Figure : Figure is the top level window or container that everything is drawn upon. Axes : Axes is the area on which we plot the data and will have associated labels and ticks. import matplotlib matplotlib.use('TkAgg') import matplotlib.pyplot as plt fig = plt.fig() ax = plt.axes() plt.show() Above code will create a new container (figure) and add an axes. We use the call plt.show() to visualize the plot. If you notice, it will be an empty bounding box with ticks (this empty box is axes). A figure can have multple axes. Axes can have 2 (X-Axis and Y-Axis) or 3 Axis objects. (3 in case of 3D) Axis : Axis is a number line object which takes care of graph limits and generating the ticks. A typical plot will start with a figure, then axes will be adde

Numpy Arrays : A quick tutorial !

Numpy is one of the most popular Python library used in Data Science and Scientific computing.  Numpy's main object is the homogeneous multidimensional array, which is a table of elements (usually numbers) of same type, indexed by a tuple of positive integers. Creating new Arrays ( array function ) New Arrays can be created by using array function. This function takes list as an argument and create N-Dimensional array based on the arguments. import numpy as np # One Dimensional Array ar1 = np.array([1,2,3]) # Two Dimensional Array ar2 = np.array([1,2,3], [4,5,6]) Other methods to create new Arrays  There are several other ways to create Arrays :- arange( [start], [stop], [step] )  This is similar to Python range function and creates evenly spaced arrays. np.arange(5) # OUT : array([0, 1, 2, 3, 4]) np.arange(2,10,2) # Excludes the stop position element # OUT : array([2, 4, 6, 8]) linspace( [start], [stop], [num] )  Creates array by number of points. np.lins