# Python Basic Plotting Tutorial # 2 : Bar Chart

For graphing a bar chart your going to need to import the two libraries Numpy and Matplotlib.

Both of these libraries can be installed by used the terminal command

pip install matplotlib

Or by going to their website Matplotlib

### Bar Chart

import matplotlib.pyplot as plt
import numpy as np

##Simple Bar Graph Example
Test = ('Test 1', 'Test 2' , 'Test 3', 'Test 4', 'Test 5')
y_axis = np.arange(len(Test))
Tests = [10,8,6,10,8]

plt.bar(y_axis , Tests, align='center', alpha=0.5, color= 'green')
plt.xticks(y_axis , Test)
plt.ylabel('Scores')
plt.title('Semester Test Scores')

plt.show()

### Double Bar Graph

##Double Bar Graph Example
Years= 4
Firm_A = (5, 3, 6, 9)
Firm_B = (7, 7, 4, 8)

# Creating plot
fig, ax = plt.subplots()
span = np.arange(Quaters)
bar_width = 0.4
opacity = 1.0

##Element one
firm_a = plt.bar(span, Firm_A, bar_width,
alpha=opacity,
color='blue',
label='Firm_A')

##Element two
firm_b = plt.bar(span + bar_width, Firm_B, bar_width,
alpha=opacity,
color='red',
label='Firm_B')

## Creating labels
plt.xlabel('Competing Firms')
plt.ylabel('Annual Revenue')
plt.title('Firm Comparison ')
plt.xticks(span + bar_width, ('Year 1', 'Year 2', 'Year 3 ', 'Year 4'))
plt.legend()

##Calling the Plotting function
plt.tight_layout()
plt.show()