Matplotlib Assignment– 3
Customization & Styling
Basic Questions
- Plot a sine wave and set the line color to #1f77b4, linestyle dashed, and marker o.
- Create a line chart with three lines and add a legend with custom labels: “Train”, “Val”, “Test”.
- Plot a scatter of 30 points using a single colormap (viridis) mapped to y-values via c= and add a colorbar.
- Draw a bar chart for 5 categories using a custom color list (five distinct hex colors).
- Plot a line chart and set a bold title, italic x-label, and monospace y-label.
- Add an annotation arrow pointing to the maximum point on a line chart with text “Peak”.
- Plot a curve and display a LaTeX-style title: $y = \alpha x^2 + \beta x + \gamma$.
- Create a line chart with markers only (no connecting line) and set marker size to 10 and edgecolor black.
- Plot a histogram and enable a grid only on the y-axis with dashed style.
- Plot any line and customize major ticks at every 2 units and minor ticks at every 0.5 units.
- Create a chart and remove the top and right spines.
- Create a chart and move the left spine to x=0 (center).
- Plot two lines and create a legend with a custom location (“upper left”) and a frame with transparency 0.5.
- Draw a scatter plot and set the background (figure facecolor) to a light gray.
- Plot a line chart and set linewidth to 3 and markerfacecolor different from markeredgecolor.
- Use a listed colormap (e.g., tab10) to color 10 distinct bars consistently by index.
- Plot a line chart and format y-axis tick labels to show percentages (e.g., “25%”).
- Plot a curve and add an annotation with a rounded box style and small padding.
- Create a line plot and set the grid to a dotted style with alpha 0.4.
- Save a line plot using a built-in style (e.g., ggplot) applied globally for the figure.
Intermediate Questions
- Plot three lines with different linestyles (-, –, 🙂 and create a custom legend using Line2D handles.
- Build a custom color palette of 6 colors and apply it to a grouped bar chart (two bars per group for 3 groups).
- Create a scatter plot with colormap plasma and normalize colors to a fixed range; add a labeled colorbar.
- Plot two subplots: first uses seaborn-v0_8-darkgrid style; second uses the default style; compare look-and-feel.
- Configure rcParams to set default font family to serif, size 12, and line width 2; plot a line to verify.
- Create a figure where x-axis uses custom tick positions [0, 2, 5, 9] and tick labels [‘A’,’B’,’C’,’D’].
- Plot a histogram and style the axis spines: make bottom thicker, left dashed, hide right and top.
- Plot a line and a scatter on the same axes with distinct markers and legend entries; set legend title “Models”.
- Draw a heatmap-like image (imshow) using the magma colormap and add a colorbar with label “Intensity”.
- Add two annotations to a line plot: one with xytext offset and arrowstyle “->”, another using bbox with “round4”.
- 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.
- Plot multiple lines and create a legend outside the axes (right side) with bbox_to_anchor.
- Customize major tick format on x-axis to show “Day 1…Day N” for integer ticks 1–7.
- Set minor ticks on both axes and style minor grid differently from major grid.
- Build a custom ListedColormap with 4 colors and use it for a categorical bar plot (map category→color).
- Use rcParams to globally set axes.grid=True, grid linestyle dotted, and grid alpha 0.3; render a line plot.
- Create a scatter plot with varying marker sizes and a legend that explains size meaning using proxy artists.
- Plot two subplots sharing y-axis but with different stylesheets (bmh and classic); add a common suptitle.
- Create a bar chart and rotate x tick labels by 45°, align them right, and reduce label size.
- 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
- Design a publication-ready theme via rcParams (fonts, linewidths, grid, figure size) and generate a multi-line chart consistent with the theme.
- Create a bespoke legend with grouped entries: one group for linestyles, one for markers, using proxy artists and a legend title.
- Implement a dual-axis chart where each axis uses its own colormap for plotted series, with separate labeled colorbars.
- Build a figure demonstrating brand colors: define a custom palette, apply across bars/lines/scatters, and add a legend key explaining each brand color.
- Construct a plot with complex math text (e.g., integral or summation) in the title and axis labels, ensuring proper spacing and baseline alignment.
- Produce a dashboard-style figure with 4 subplots; customize tick locators/formatters differently in each (linear, log, dates, percent).
- Create a style-switcher demo: render the same timeseries under three styles (default, seaborn-v0_8, ggplot) and save all variants.
- Develop an advanced annotations showcase: arrows with different arrowstyle, connectionstyle, bbox styles, and anchored text; label features on the plot.
- Customize all spines (positions, visibility, linewidth, colors) to frame the data region uniquely; include a legend outside and custom tick lengths/directions.
- 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.