Python practice: Business Visualizations with Matplotlib
Chapter 29 · 8 questions · included in full access
Question 1 · easy
Figure vs Axes in Matplotlib
Solve it in your browserIn Matplotlib's object-oriented architecture (
fig, ax = plt.subplots()), what is the difference between the Figure and the Axes?Question 2 · easy
Plot a vertical bar chart of regional revenue
Solve it in your browserCreate a bar chart using
fig, ax = plt.subplots(). Plot regions["North", "South", "West", "East"]with revenue[140650, 123250, 118800, 89700]usingax.bar(). Print the count of bar patches created (len(ax.patches)):Question 3 · medium
Horizontal bar chart for product categories
Solve it in your browserCreate a horizontal bar chart with
fig, ax = plt.subplots(). Plot categories["Sheets", "Profiles", "Accessories"]and revenue[343200, 66500, 62700]usingax.barh(). Printlen(ax.patches):Question 4 · easy
Line plot for monthly revenue trend
Solve it in your browserLoad
"sales.csv", parseDatewithpd.to_datetime. Compute totalRevenuegrouped by month (sales["Date"].dt.month). Create a line plot withfig, ax = plt.subplots(),ax.plot(by_month.index, by_month.values). Print Month 3 revenue (int(by_month[3])):Question 5 · medium
Professional chart styling with titles and grid
Solve it in your browserCreate a line plot of
[1, 2, 3]and[10, 20, 30]. Set the title to"Quarterly Trend"usingax.set_title(), set x-label to"Quarter", y-label to"Revenue", and enable grid withax.grid(True). Printax.get_title():Question 6 · medium
Multi-panel layout with subplots(1, 2)
Solve it in your browserCreate a multi-panel figure with 1 row and 2 columns:
fig, axes = plt.subplots(1, 2). Plot a bar chart onaxes[0]with["A", "B"]and[10, 20], and a line plot onaxes[1]with[1, 2]and[10, 20]. Printlen(axes):Question 7 · medium
Rotate x-axis tick labels for readability
Solve it in your browserCreate a bar chart of
["North Region", "South Region"]and[100, 200]. Rotate x tick labels 45 degrees usingax.tick_params(axis="x", rotation=45). Force draw withplt.draw(). Print the rotation angle of the first tick label (int(ax.get_xticklabels()[0].get_rotation())):Question 8 · hard
Export high-resolution boardroom visual
Solve it in your browserCreate a plot with
fig, ax = plt.subplots(), plot[1, 2]and[3, 4]. Save the figure as"report.png"with 300 DPI resolution usingfig.savefig("report.png", dpi=300). Check if the file exists usingimport os; print(os.path.exists("report.png")):
These questions are part of full access.
The first chapters of every track are free. Full access is a one-time payment.
See pricing