In the lesson of Introduction to Matplotlib, in side-by-side bars lesson, I tried to label the x-axis but it did not work - see my code below. It shows the pot alright but I cannot make it to show the labels. The last three lines of codes do not make any changes in the plot!
The lesson, unfortunately, does not show how to create a label for the x-axis in the side-by-side bar plot. Then, I tried to use the same code on my computer. Now I get a strange error. It says plt.show() is a syntax error!!
I appreciate any help.
My code:
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.8 # Width of each bar
store1_x = [telement + wn for element
in range(d)]
plt.bar(store1_x, sales1)
n = 2 # This is our first dataset (out of 2)
t = 2 # Number of datasets
d = 6 # Number of sets of bars
w = 0.8 # Width of each bar
store2_x = [telement + wn for element
in range(d)]
plt.bar(store2_x, sales2)
ax = plt.subplot()
ax.set_xticklabels(drinks)
ax.set_xticks(range(len(drinks))
plt.show()