import numpy as np
import matplotlib.pyplot as plt
ages = np.array([5, 25, 45, 20, 15])
names = np.array(['John', 'Maria', 'Priyanka', 'Martha', 'Matts'])
plt.bar(names, ages)
plt.show()
plt.bar(names, ages, color = "red")
plt.show()
color = np.array(["red", "purple", "green", "yellow", "blue"])
plt.bar(names, ages, color = color)
plt.show()
plt.bar(names, ages, color = color)
plt.title("Name and Age Bar Graph")
plt.xlabel("Names")
plt.ylabel("Ages")
plt.show()
plt.bar(names, ages, color = color)
plt.title("Name and Age Bar Graph", fontsize = 20)
plt.xlabel("Names", fontsize = 15)
plt.ylabel("Ages", fontsize = 15)
plt.show()
plt.bar(ages, names)
plt.show()
ages = np.array([5, 25, 45, 20, 15])
names = np.array(['John', 'Maria', 'Priyanka', 'Martha', 'Matts'])
plt.barh(names, ages)
plt.show()
x = np.arange(4)
y = np.random.rand(4)
print(x)
print(y)
plt.bar(x, y)
plt.show()
x = np.arange(5)
y = np.random.rand(4, 5)
print(x)
print(y)
plt.bar(x + 0.00, y[0], color = 'b', width = 0.25)
plt.bar(x + 0.25, y[1], color = 'g', width = 0.25)
plt.bar(x + 0.50, y[2], color = 'r', width = 0.25)
plt.show()
grade = ["III", "IV", "V", "VI", "VII"]
score = [60, 40, 50, 78, 90]
position_of_grade = np.arange(len(grade))
plt.bar(position_of_grade, score)
plt.show()
grade = ["III", "IV", "V", "VI", "VII"]
score = [60, 40, 50, 78, 90]
position_of_grade = np.arange(len(grade))
plt.bar(position_of_grade, score)
plt.xticks(position_of_grade, grade)
plt.title('Barchart - Score by Grade',fontsize=20)
plt.xlabel('Grade', fontsize=15)
plt.ylabel('Score in %', fontsize=15)
plt.show()
grade = ["III", "IV", "V", "VI", "VII"]
score = [60, 40, 50, 78, 90]
color = ["red", "purple", "green", "yellow", "blue"]
position_of_grade = np.arange(len(grade))
plt.bar(position_of_grade, score, color = color, edgecolor = 'red')
plt.xticks(position_of_grade, grade)
plt.title('Barchart - Score by Grade',fontsize = 20)
plt.xlabel('Grade', fontsize = 15)
plt.ylabel('Score in %', fontsize = 15)
plt.show()
linestyle description
'-' or 'solid' solid line '--' or 'dashed' dashed line '-.' or 'dashdot' dash-dotted line ':' or 'dotted' dotted line
grade = ["III", "IV", "V", "VI", "VII"]
score = [60, 40, 50, 78, 90]
color = ["red", "purple", "green", "yellow", "blue"]
position_of_grade = np.arange(len(grade))
plt.bar(position_of_grade, score, color = color, edgecolor = 'red', linestyle = '--')
plt.xticks(position_of_grade, grade)
plt.title('Barchart - Score by Grade',fontsize = 20)
plt.xlabel('Grade', fontsize = 15)
plt.ylabel('Score in %', fontsize = 15)
plt.show()
grade = ["III", "IV", "V", "VI", "VII"]
score = [60, 40, 50, 78, 90]
color = ["red", "purple", "green", "yellow", "blue"]
position_of_grade = np.arange(len(grade))
plt.bar(position_of_grade, score, color = color, edgecolor = 'red', linestyle = '--', alpha = 0.4, linewidth = 2)
plt.xticks(position_of_grade, grade)
plt.title('Barchart - Score by Grade',fontsize = 20)
plt.xlabel('Grade', fontsize = 15)
plt.ylabel('Score in %', fontsize = 15)
plt.show()
grade = ["III", "IV", "V", "VI", "VII"]
#score = [60, 40, 50, 78, 90]
score_male = [40, 60, 30, 65, 85]
score_female = [50, 70, 80, 55, 75]
position_of_grade = np.arange(len(grade))
plt.bar(position_of_grade, score_male, color = "#00bfff", edgecolor = 'red')
plt.bar(position_of_grade, score_female, color = "#bf00ff", edgecolor = 'red', bottom = score_male)
plt.xticks(position_of_grade, grade)
plt.title('Barchart - Score by Grade',fontsize = 20)
plt.xlabel('Grade', fontsize = 15)
plt.ylabel('Score in %', fontsize = 15)
plt.show()
Location String Location Code
'best' 0 'upper right' 1 'upper left' 2 'lower left' 3 'lower right' 4 'right' 5 'center left' 6 'center right' 7 'lower center' 8 'upper center' 9 'center' 10
grade = ["III", "IV", "V", "VI", "VII"]
#score = [60, 40, 50, 78, 90]
Gender=['Male','Female']
score_male = [40, 60, 30, 65, 85]
score_female = [50, 70, 80, 55, 75]
position_of_grade = np.arange(len(grade))
plt.bar(position_of_grade, score_male, color = "#00bfff", edgecolor = 'red')
plt.bar(position_of_grade, score_female, color = "#bf00ff", edgecolor = 'red', bottom = score_male)
plt.xticks(position_of_grade, grade)
plt.title('Barchart - Score by Grade',fontsize = 20)
plt.xlabel('Grade', fontsize = 15)
plt.ylabel('Score in %', fontsize = 15)
plt.legend(Gender,loc=2)
plt.show()
A survey of 100 people asked them "Which is the nicest fruit?":
Fruit: Apple Orange Banana Mango Watermelon Grapes
People: 30 10 10 20 5 25
fruits = ["Apple", "Orange", "Banana", "Mango", "Watermelon", "Grapes"]
fruits
no_of_people = [30, 10, 10, 20, 5, 25]
no_of_people
color = ["#33f6ff", "#a5ff33", "#ee42d4", "#e7f121", "#f83a10", "#3f41f1"]
plt.bar(fruits, no_of_people, color = color)
plt.xticks(fruits)
plt.title('Barchart - Which is the nicest fruit?',fontsize=20)
plt.xlabel('Fruits', fontsize=15)
plt.ylabel('Number of People', fontsize=15)
plt.show()
Top Performing States in 2018 No State Literacy Rate in Percentage 1 Kerala 96.2% 2 Delhi 88.7% 3 Uttarakhand 87.6% 4 Himachal Pradesh 86.6% 5 Assam 85.9% 6 Maharashtra 84.8%
states = ["Kerala", "Delhi", "Uttarakhand", "Himachal Pradesh", "Assam", "Maharashtra"]
states
literacy_rate = [96.2, 88.7, 87.6, 86.6, 85.9, 84.8]
literacy_rate
color = ["#33f6ff", "#a5ff33", "#ee42d4", "#e7f121", "#f83a10", "#3f41f1"]
plt.figure(figsize=(10, 6))
plt.bar(states, literacy_rate, color = color)
plt.xticks(states)
plt.title('Top Performing States in 2018',fontsize=20)
plt.xlabel('State', fontsize=15)
plt.ylabel('Literacy Rate in Percentage', fontsize=15)
plt.show()
The adult and youth literacy rates for India and some neighboring countries in 2015. Adult literacy rate is based on the 15+ years age group, while the youth literacy rate is for the 15–24 years age group.
UNESCO list of countries by literacy rate (2015) Country Adult literacy rate Youth literacy rate ages 15–24 China 96.4% 99.7% Sri Lanka 92.6% 98.8% Myanmar 93.7% 96.3% World average 86.3% 91.2% India 81% 91.66% Nepal 64.7% 86.9% Bangladesh 61.5% 83.2% Pakistan 58% 80.3%
This data is taken from wikipedia https://en.wikipedia.org/wiki/Literacy_in_India.
countries = ["China", "Sri Lanka", "Myanmar", "World average", "India", "Nepal", "Bangladesh", "Pakistan"]
adult_literacy_rate = [96.4, 92.6, 93.7, 86.3, 81, 64.7, 61.5, 58]
color = ["#33f6ff", "#a5ff33", "#ee42d4", "#e7f121", "#f83a10", "#3f41f1", "#ef24d4", "#e3f124"]
plt.figure(figsize=(10, 6))
plt.bar(countries, adult_literacy_rate, color = color)
plt.xticks(countries)
plt.title('UNESCO list of countries by literacy rate (2015) ',fontsize=20)
plt.xlabel('Countries', fontsize=15)
plt.ylabel('Adult Literacy Rate in Percentage', fontsize=15)
plt.show()
adult_literacy_rate_ages_15_to_24 = [99.7, 98.8, 96.3, 91.2, 91.66, 86.9, 83.2, 80.3]
import seaborn as sns
colors= sns.color_palette("husl", 8)
colors
plt.figure(figsize=(10, 6))
plt.bar(countries, adult_literacy_rate_ages_15_to_24, color = colors)
plt.xticks(countries)
plt.title('UNESCO List of Countries by Literacy Rate Ages 15–24 (2015) ',fontsize=18)
plt.xlabel('Countries', fontsize=12)
plt.ylabel('Youth Literacy Rate Ages 15–24 in Percentage', fontsize=12)
plt.show()
fig, (ax1, ax2) = plt.subplots(1, 2)
fig.set_figwidth(20)
ax1.bar(countries, adult_literacy_rate, color = color)
ax1.set_title("Adult Literacy Rate")
ax2.bar(countries, adult_literacy_rate_ages_15_to_24, color = color)
ax2.set_title("Youth Literacy Rate")
fig.suptitle('UNESCO List of Countries by Literacy Rate Ages 15+ and 15–24 (2015)', fontsize = 20)
plt.show()