Plotting Line Graph, Bar Graph, Histogram, Box Graph, and Heat Map in Data Science and ML

In this blog, we will learn how to plot graphs in data science using pandas, sklearn, and matplotlib.


Plotting Line Graph


#plotting line graph


plt.plot(path_of_csv['Column name of csv '])

plt.xlabel('x')

plt.ylabel('y')

label = ['jan', 'feb', 'mar']

plt.xticks(np.arange(0, 50, 5), label)

plt.yticks(np.arange(0, 100, 25))

plt.title('your title here')

plt.show()


or


Without CSV:


field = [1,2,3]

plt.plot(field)

plt.xlabel('x')

plt.ylabel('y')

label = ['jan', 'feb', 'mar']

plt.xticks(np.arange(0, 10, 2), label)

plt.yticks(np.arange(0, 75, 25))

plt.title('your title here')

plt.show()


The plot display like this:

Plotting Box Graph:


#Ploting Box graph


Using CSV:


Data = read_csv("csv_file")


plt.figure(figsize=(10,8))

Data.boxplot('column_name', vert=False)

or #sns.boxplot(x='x', y='y', data=Data)

plt.xlabel('x')

plt.title('your title here')

plt.show()




Plotting Histogram Graph:


#Ploting Histogram graph


Using CSV:


#Ploting histogram


plt.figure(figsize=(20,10))

Data ['columnname'].plot.hist(bins=50,

color='#607c8e')

plt.yticks([0,250,500])

plt.xlabel('x')

plt.title('write title hre')

plt.ylabel('y')




Plotting Heat-map:


#Ploting Heat-map


Using CSV:


Code:


csv_file_data = read_csv("filename")


Data = csv_file_data [ csv_file_data ['Days']


data_table = Data .pivot_table(index=Data['date'].dt.hour,

columns='Data_column1',

values='Data_column2',

aggfunc='sum')


fig, ax = plt.subplots()


ax.set_title('write title here')


heatmap1 = ax.pcolor(data_table )

plt.colorbar(heatmap1)


plt.yticks(np.arange(0, len(data_table .index), 1), data_table .index)

plt.xticks(np.arange(0, len(data_table .columns), 1), data_table .columns)


plt.show()


It look like that:


Thanks for reading this, if you need any help related to the data science graph then please contact here or comments below if suggests anything related to the plot.


Contact Us

Tel: (+91) 0120  4118730  

Time :   10 : 00  AM -  08 : 00 PM IST 

Registered address: G-69, Sector 63, 

 Noida - 201301, India

We Provide Services Across The different countries

USA    Australia   Canada   UK    UAE    Singapore   New Zealand    Malasia   India   Ireland   Germany

CodersArts is a Product by Sofstack Technology Solutions Pvt. Ltd.

  • CodersArts | Linkedin
  • Instagram