Python practice: Business Visualizations with Matplotlib

Chapter 29 · 8 questions · included in full access

  1. Question 1 · easy

    Figure vs Axes in Matplotlib

    In Matplotlib's object-oriented architecture (fig, ax = plt.subplots()), what is the difference between the Figure and the Axes?

    Solve it in your browser
  2. Question 2 · easy

    Plot a vertical bar chart of regional revenue

    Create a bar chart using fig, ax = plt.subplots(). Plot regions ["North", "South", "West", "East"] with revenue [140650, 123250, 118800, 89700] using ax.bar(). Print the count of bar patches created (len(ax.patches)):

    Solve it in your browser
  3. Question 3 · medium

    Horizontal bar chart for product categories

    Create a horizontal bar chart with fig, ax = plt.subplots(). Plot categories ["Sheets", "Profiles", "Accessories"] and revenue [343200, 66500, 62700] using ax.barh(). Print len(ax.patches):

    Solve it in your browser
  4. Question 4 · easy

    Line plot for monthly revenue trend

    Load "sales.csv", parse Date with pd.to_datetime. Compute total Revenue grouped by month (sales["Date"].dt.month). Create a line plot with fig, ax = plt.subplots(), ax.plot(by_month.index, by_month.values). Print Month 3 revenue (int(by_month[3])):

    Solve it in your browser
  5. Question 5 · medium

    Professional chart styling with titles and grid

    Create a line plot of [1, 2, 3] and [10, 20, 30]. Set the title to "Quarterly Trend" using ax.set_title(), set x-label to "Quarter", y-label to "Revenue", and enable grid with ax.grid(True). Print ax.get_title():

    Solve it in your browser
  6. Question 6 · medium

    Multi-panel layout with subplots(1, 2)

    Create a multi-panel figure with 1 row and 2 columns: fig, axes = plt.subplots(1, 2). Plot a bar chart on axes[0] with ["A", "B"] and [10, 20], and a line plot on axes[1] with [1, 2] and [10, 20]. Print len(axes):

    Solve it in your browser
  7. Question 7 · medium

    Rotate x-axis tick labels for readability

    Create a bar chart of ["North Region", "South Region"] and [100, 200]. Rotate x tick labels 45 degrees using ax.tick_params(axis="x", rotation=45). Force draw with plt.draw(). Print the rotation angle of the first tick label (int(ax.get_xticklabels()[0].get_rotation())):

    Solve it in your browser
  8. Question 8 · hard

    Export high-resolution boardroom visual

    Create a plot with fig, ax = plt.subplots(), plot [1, 2] and [3, 4]. Save the figure as "report.png" with 300 DPI resolution using fig.savefig("report.png", dpi=300). Check if the file exists using import os; print(os.path.exists("report.png")):

    Solve it in your browser

These questions are part of full access.

The first chapters of every track are free. Full access is a one-time payment.

See pricing