Docsity

matplotlib tutorial in jupyter notebook, Cheat Sheet of Computer Programming

Toggle sidebar
bg1
How to visulize Data using matplotlib in python3
This is basic tutorial for plotting or visualizing data in python using matplotlib library
HopeFully you like this very basic tutorial of matplotlib. Next tutorial will be of little advance level.
In [1]:
# importing libraries
# '%matplotlib inline' is used for using the jupyter notebook as canvas or plotting ground
%matplotlib inline
import matplotlib.pyplot as plt
import math
In [2]:
x=[0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]
y=x
y1=[i**2 for i in x]
y2=[i**3 for i in x]
y3=[i+0.5 for i in x]
In [3]:
# plotting x verses y also we can plot multiple vectors in single plot, just add plots like below
plt.plot(x,y)
plt.plot(x,y1)
plt.plot(x,y2)
plt.plot(x,y3)
plt.show()
In [4]:
# if we want to see data points as markers on plot we will use different marker styles as below, markers are 'o','+','*' while
# '-' symbol with marker shows connection of marker points, you can the marker size also as shown in (x,y)
plt.plot(x,y,'o-',markersize=15)
plt.plot(x,y1,'+--')
plt.plot(x,y2,'*-')
plt.plot(x,y3,'d--')
# setting figure labels
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.title('Multiple plots in Single Figure')
plt.grid(visible=True)
plt.show()
In [ ]:

Partial preview of the text

Download matplotlib tutorial in jupyter notebook and more Cheat Sheet Computer Programming in PDF only on Docsity!

How to visulize Data using matplotlib in python

This is basic tutorial for plotting or visualizing data in python using matplotlib library

HopeFully you like this very basic tutorial of matplotlib. Next tutorial will be of little advance level.

In [1]: # importing libraries

'%matplotlib inline' is used for using the jupyter notebook as canvas or plotting ground

%matplotlib inline import matplotlib.pyplot as plt import math

In [2]: x = [0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0] y = x y1 = [i ****** 2 for i in x] y2 = [i ****** 3 for i in x] y3 = [i + 0.5 for i in x]

In [3]: # plotting x verses y also we can plot multiple vectors in single plot, just add plots like below plt. plot(x,y) plt. plot(x,y1) plt. plot(x,y2) plt. plot(x,y3) plt. show()

In [4]: # if we want to see data points as markers on plot we will use different marker styles as below, markers are 'o','+','*' while

'-' symbol with marker shows connection of marker points, you can the marker size also as shown in (x,y)

plt. plot(x,y,'o-',markersize = 15) plt. plot(x,y1,'+--') plt. plot(x,y2,'-') plt.* plot(x,y3,'d--')

setting figure labels

plt. xlabel('X axis') plt. ylabel('Y axis') plt. title('Multiple plots in Single Figure') plt. grid(visible =True ) plt. show()

In [ ]: