-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotting side by side bar charts
More file actions
63 lines (53 loc) · 1.87 KB
/
Plotting side by side bar charts
File metadata and controls
63 lines (53 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from matplotlib import pyplot as plt
import numpy as np
drinks = ["cappuccino", "latte", "chai", "americano", "mocha", "espresso"]
sales1 = [91, 76, 56, 66, 52, 27]
sales2 = [65, 82, 36, 68, 38, 40]
#Paste the x_values code here
n = 1 # This is our first dataset (out of 2)
t = 2 # Number of datasets
d = 6 # Number of sets of bars
w =0 # Width of each bar
store1_x = [t*element + w*n for element
in range(d)]
plt.bar(store1_x,sales1)
n=2
t=2
d=len(sales1)
w= 0.8
store2_x=[t*x +w for x in range(d)]
plt.title('Sales of drink at 2 store locations by types')
plt.xlabel('Drinks')
plt.ylabel('Sales')
plt.bar(store2_x,sales2)
plt.show()
drinks = ["cappuccino", "latte", "chai", "americano", "mocha", "espresso"]
ounces_of_milk = [6, 9, 4, 0, 9, 0]
error = [0.6, 0.9, 0.4, 0, 0.9, 0]
# Plot the error bar graph here
plt.bar(range(len(drinks)),ounces_of_milk, yerr=error, capsize=5)
plt.title('Error in drink measurements')
plt.xlabel('Drinks')
plt.ylabel('Ounce of milk')
plt.legend("drinkmeasurements")
plt.show()
#Creating a shaded value-interval/ maximum and minimal bounds for values
months = range(12)
month_names = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
revenue = [16000, 14000, 17500, 19500, 21500, 21500, 22000, 23000, 20000, 19500, 18000, 16500]
#your work here
plt.plot(months, revenue)
y_lower=[.9*y for y in revenue]
y_upper=[1.1*y for y in revenue]
plt.fill_between(months,y_lower,y_upper,alpha=.2)
ax=plt.subplot()
ax.set_xticks(months)
ax.set_xticklabels(month_names)
plt.show()
#Creating a labeled pie chart with legends and percentages displayed to present share-of-the-total visuals
payment_method_names = ["Card Swipe", "Cash", "Apple Pay", "Other"]
payment_method_freqs = [270, 77, 32, 11]
plt.pie(payment_method_freqs, labels =payment_method_names,autopct='%.1f%%')
plt.axis('equal')
plt.legend(payment_method_names)
plt.show()