Python - Graph Plotting - Code
Python - Graph Plotting - Code
()
-----------------
# importing the required module
import matplotlib.pyplot as plt
# x axis values
x = [1, 2, 3]
# corresponding y axis values
y = [2, 4, 1]
# line 1 points
x1 = [1, 2, 3]
y1 = [2, 4, 1]
# plotting the line 1 points
plt.plot(x1, y1, label="line 1")
# line 2 points
x2 = [1, 2, 3]
y2 = [4, 1, 3]
# plotting the line 2 points
plt.plot(x2, y2, label="line 2")
# x axis values
x = [1, 2, 3, 4, 5, 6]
# corresponding y axis values
y = [2, 4, 1, 5, 2, 6]
# frequencies
ages = [2, 5, 70, 40, 30, 45, 50, 45, 43, 40, 44,
60, 7, 13, 57, 18, 90, 77, 32, 21, 20, 40]
# plotting a histogram
plt.hist(ages, bins, range, color='green',
histtype='bar', rwidth=0.8)
# x-axis label
plt.xlabel('age')
# frequency label
plt.ylabel('No. of people')
# plot title
plt.title('My histogram')
# defining labels
activities = ['eat', 'sleep', 'work', 'play']
# plotting legend
plt.legend()