How To Create Charts In Python



In this post we are going to make Charts in Python using matplotlib & pandas. If you don't know what is matplotlib don't worry. I will explain matplotlib is a module used to make charts like Bar Charts & Histogram. If you don't know how to install matplotlib. I will tell you how to install. Type "pip install matplotlib" in Command Prompt or Terminal. The module matplotlib is install on your Python.

Modules Needed To Import:-

1. import matplot.pyplot as plt

2.import pandas as pd

Here Is The Code:-

import matplotlib.pyplot as plt
import pandas as pd
Data = {'Country': ['USA','India','Japan','Russia','France','Pakistan'],
        'GDP_Per_Capita': [45000,60000,52000,49000,47000,-199]
       }
df = pd.DataFrame(Data,columns=['Country','GDP_Per_Capita'])

New_Colors = ['orange','blue','green','brown','red','black']
plt.bar(df['Country'], df['GDP_Per_Capita'], color=New_Colors)
plt.title('Country Vs GDP Per Capita', fontsize=14)
plt.xlabel('Country', fontsize=14)
plt.ylabel('GDP Per Capita', fontsize=14)
plt.show()

Output



Post a Comment

Previous Post Next Post