Hello, everyone. This is the lesson i´ve been digging into.
Everything went smoothly for what was requested in the lesson, i got problems when i tried to improve by adjusting the x-axis with labels and correct it’s position (set the ticks in the middle of the bars) but everything i did didn’t change the result.
This is my code
import codecademylib from matplotlib import pyplot as plt 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 = [t*element + w*n for element in range(d)] plt.bar(store1_x, sales1) n = 2 # This is our second 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 = [t*element + w*n for element in range(d)] plt.bar(store2_x, sales2) plt.show()
I tried using the
ax = plt.subplot() to change but nothing happened.
ax = plt.subplot() ax.set_xticks(range(len(drinks))) ax.set_xticklabels(drinks)
I tried putting after both
store2_x blocks of code, but nothing happened with the results, i didn’t get an error, but the result didn’t change either. What is going on here? Is this something about my ax code or is the ticks and labels changed in other way for side by side bars?
Another quick question if i may, when defining the d (this doesn’t sound very good, but i don’t know how else to say this) in the
store_x blocks, i tried using
range(len(drinks)) to get the number but the lesson didn’t accept as a correct answer. Why? Can’t i use this method to save me time in this case?