Class 2 Data Visualization in Python using matplotlib
Class 2 Data Visualization in Python using matplotlib
The scatter chart can be created through two functions of pyplot library:
i. The plot() function
ii. The scatter() function
In plot() whenever you specify marker type/style, whether with colour or without colour,
and do not give linestyle argument, plot creates a scatter chart.
For example:
when linestyle is specified In absence of linestyle
import matplotlib.pyplot as pl import matplotlib.pyplot as pl
marks=[78,67,98,55,88] marks=[78,67,98,55,88]
test=[1,2,3,4,5]
test=[1,2,3,4,5]
pl.xlabel('test')
pl.xlabel('test')
pl.ylabel('Marks')
pl.title('Marks Analysis') pl.ylabel('Marks')
pl.plot(test,marks,color='y',linestyle='solid', pl.title('Marks Analysis')
linewidth=4,marker='P',markeredgecolor='r') pl.plot(test,marks,'r+')
pl.show() pl.show()
Q2 Write a program to plot a scatter graph taking a random distribution in X and Y(both
with shape as (250) having randomly generated integers and plotted against each other
with varying sizes and varying colors.
import numpy as np
import matplotlib.pyplot as pl
X=np.random.randint(1,100,size=(250,))
Y=np.random.randint(1,100,size=(250,))
size=range(1,60,5)
color123=['r','b','c','y','k','g']
pl.scatter(X,Y,color=color123,s=size)
pl.xlabel("Values of X")
pl.ylabel("Values of Y")
pl.show()
Q3 Write a program to plot a scatter graph taking three random distribution in X1,y1 and
Z1(all three with shape as (250) having randomly generated integers) and plotted against
each other with varying sizes.
import numpy as np
import matplotlib.pyplot as pl
X=np.random.randint(1,100,size=(250,))
Y=np.random.randint(1,100,size=(250,))
Z=np.random.randint(1,100,size=(250,))
size=range(1,60,5)
pl.scatter(X,Y,color='r',s=size)
pl.scatter(X,Z,color='b',s=size)
pl.xlabel("Values of X")
pl.ylabel("Values of Y and Z")
pl.show()