10. Data Plotting and Visualization
10. Data Plotting and Visualization
September 8, 2019
# x axis values
x = [1,2,3,4,5]
# corresponding y axis values
y = [2,4,1,3,4]
1
[3]: #BAR CHART
# heights of bars
height = [10, 24, 36, 40, 23]
2
[4]: #HISTOGRAM
# load frequencies
load = [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(load, bins, range, color = 'green',
histtype = 'bar', rwidth = 0.8)
# x-axis label
plt.xlabel('Hours')
# frequency label
plt.ylabel('Weekly ')
# plot title
plt.title('Consumption of Electricity')
3
plt.show()
# defining labels
Load_consumption = ['East', 'South', 'West', 'North']
# plotting legend
4
#plt.legend()
5
[8]: #Plotting two or more lines on same plot
# 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")
6
# function to show the plot
plt.show()
# x-axis values
x = [1,2,3,4,5,6,7,8,9,10]
# y-axis values
y = [2,4,5,7,6,8,9,11,12,12]
# x-axis label
plt.xlabel('x - axis')
# frequency label
plt.ylabel('y - axis')
# plot title
plt.title('My scatter plot!')
7
# showing legend
plt.legend()
2 References:
https://matplotlib.org/
https://github.com/