Matplotlib Assignment– 3

Customization & Styling

Basic Questions

  1. Plot a sine wave and set the line color to #1f77b4, linestyle dashed, and marker o.
  2. Create a line chart with three lines and add a legend with custom labels: “Train”, “Val”, “Test”.
  3. Plot a scatter of 30 points using a single colormap (viridis) mapped to y-values via c= and add a colorbar.
  4. Draw a bar chart for 5 categories using a custom color list (five distinct hex colors).
  5. Plot a line chart and set a bold title, italic x-label, and monospace y-label.
  6. Add an annotation arrow pointing to the maximum point on a line chart with text “Peak”.
  7. Plot a curve and display a LaTeX-style title: $y = \alpha x^2 + \beta x + \gamma$.
  8. Create a line chart with markers only (no connecting line) and set marker size to 10 and edgecolor black.
  9. Plot a histogram and enable a grid only on the y-axis with dashed style.
  10. Plot any line and customize major ticks at every 2 units and minor ticks at every 0.5 units.
  11. Create a chart and remove the top and right spines.
  12. Create a chart and move the left spine to x=0 (center).
  13. Plot two lines and create a legend with a custom location (“upper left”) and a frame with transparency 0.5.
  14. Draw a scatter plot and set the background (figure facecolor) to a light gray.
  15. Plot a line chart and set linewidth to 3 and markerfacecolor different from markeredgecolor.
  16. Use a listed colormap (e.g., tab10) to color 10 distinct bars consistently by index.
  17. Plot a line chart and format y-axis tick labels to show percentages (e.g., “25%”).
  18. Plot a curve and add an annotation with a rounded box style and small padding.
  19. Create a line plot and set the grid to a dotted style with alpha 0.4.
  20. Save a line plot using a built-in style (e.g., ggplot) applied globally for the figure.

Intermediate Questions

  1. Plot three lines with different linestyles (-, –, 🙂 and create a custom legend using Line2D handles.
  2. Build a custom color palette of 6 colors and apply it to a grouped bar chart (two bars per group for 3 groups).
  3. Create a scatter plot with colormap plasma and normalize colors to a fixed range; add a labeled colorbar.
  4. Plot two subplots: first uses seaborn-v0_8-darkgrid style; second uses the default style; compare look-and-feel.
  5. Configure rcParams to set default font family to serif, size 12, and line width 2; plot a line to verify.
  6. Create a figure where x-axis uses custom tick positions [0, 2, 5, 9] and tick labels [‘A’,’B’,’C’,’D’].
  7. Plot a histogram and style the axis spines: make bottom thicker, left dashed, hide right and top.
  8. Plot a line and a scatter on the same axes with distinct markers and legend entries; set legend title “Models”.
  9. Draw a heatmap-like image (imshow) using the magma colormap and add a colorbar with label “Intensity”.
  10. Add two annotations to a line plot: one with xytext offset and arrowstyle “->”, another using bbox with “round4”.
  11. Create a plot with math text on both axes labels, e.g., $t$ (s) and $v(t)$ (m/s), and a LaTeX formula in the title.
  12. Plot multiple lines and create a legend outside the axes (right side) with bbox_to_anchor.
  13. Customize major tick format on x-axis to show “Day 1…Day N” for integer ticks 1–7.
  14. Set minor ticks on both axes and style minor grid differently from major grid.
  15. Build a custom ListedColormap with 4 colors and use it for a categorical bar plot (map category→color).
  16. Use rcParams to globally set axes.grid=True, grid linestyle dotted, and grid alpha 0.3; render a line plot.
  17. Create a scatter plot with varying marker sizes and a legend that explains size meaning using proxy artists.
  18. Plot two subplots sharing y-axis but with different stylesheets (bmh and classic); add a common suptitle.
  19. Create a bar chart and rotate x tick labels by 45°, align them right, and reduce label size.
  20. Use a custom style file (.mplstyle) or a built-in style and compare the visual with and without the style in two figures.

Advanced Questions

  1. Design a publication-ready theme via rcParams (fonts, linewidths, grid, figure size) and generate a multi-line chart consistent with the theme.
  2. Create a bespoke legend with grouped entries: one group for linestyles, one for markers, using proxy artists and a legend title.
  3. Implement a dual-axis chart where each axis uses its own colormap for plotted series, with separate labeled colorbars.
  4. Build a figure demonstrating brand colors: define a custom palette, apply across bars/lines/scatters, and add a legend key explaining each brand color.
  5. Construct a plot with complex math text (e.g., integral or summation) in the title and axis labels, ensuring proper spacing and baseline alignment.
  6. Produce a dashboard-style figure with 4 subplots; customize tick locators/formatters differently in each (linear, log, dates, percent).
  7. Create a style-switcher demo: render the same timeseries under three styles (default, seaborn-v0_8, ggplot) and save all variants.
  8. Develop an advanced annotations showcase: arrows with different arrowstyle, connectionstyle, bbox styles, and anchored text; label features on the plot.
  9. Customize all spines (positions, visibility, linewidth, colors) to frame the data region uniquely; include a legend outside and custom tick lengths/directions.
  10. Produce a polished “report figure”: apply a global stylesheet, custom rcParams overrides, unified color cycle, consistent typography, fine-tuned grids/ticks/spines, and export to PNG (300 DPI) and PDF.