FAQ: Different Plot Types - Simple Bar Chart II

This community-built FAQ covers the “Simple Bar Chart II” exercise from the lesson “Different Plot Types”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Data Visualization in Python

FAQs on the exercise Simple Bar Chart II

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

What does ax = plt.subplot() create when no arguments are given to it? Does it default to whatever was plotted directly before that argument was made? In this case plt.bar(range(len(drinks)), sales)?
If so, is that why if I pass in parameters other than 1,1,1 into subplot, the resulting graph doesn’t display y values? If I do ax = plt.subplot(2,2,1), is this creating a new figure over my plt.bar(range(len(drinks)), sales) graph?

Also, why do I need to have the command ax.set_xticks(range(6))? Isn’t that already the case before we make this argument based on the first parameter in my plt.bar command? It doesn’t work so obviously not, but I don’t understand why. It seems like ax = plt.subplot() knows to take some of the info from plt.bar(range(len(drinks)), sales), but that we have to fill in some info it missed out on.

I hope I’m being clear in what I am asking!

2 Likes

why does the x axis not pick up the first element of the dribks list if ax.set_xticklabels() is not preceeded by ax.xticks() for the bar chart

Because you have to set the x tick locations/marks before you label the x ticks.

See:
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.xticks.html

And more:
https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_xticks.html

1 Like