MatplotLib Assignment– 4

Advanced Plot Types

Basic Questions

  1. Plot a histogram of 200 random integers between 1 and 10 with 10 bins; show frequency on y-axis.
  2. Plot a normalized histogram (density=True) of 500 values drawn from a normal distribution (μ=0, σ=1).
  3. Overlay two histograms (normal vs. uniform, 500 samples each) with transparency to compare distributions.
  4. Create a simple density line by plotting the normalized histogram (as step) of normal data with 30 bins.
  5. Plot a KDE curve for 300 normal samples (use scipy.stats.gaussian_kde if available; otherwise skip).
  6. Draw a boxplot of exam scores for 1 class (list of 25 values you define or randomly generate).
  7. Draw side-by-side boxplots comparing two classes (Class A vs Class B, 25 scores each).
  8. Plot a violin plot for three groups (A, B, C) with 50 samples each from different normal means.
  9. Create a stem plot for the discrete sequence y = [3, 1, 4, 1, 5, 9, 2].
  10. Plot a line with error bars (means = [5,7,6,8], std = [0.5,1.0,0.3,0.8]) using plt.errorbar.
  11. Create a pie chart of market share for 5 brands with labels and percentage autopct.
  12. Create a donut chart (pie with a white circle in the center) for the same market share data.
  13. Plot a polar line chart for r = 1 + 0.5*cos(θ) where θ ∈ [0, 2π].
  14. Create a basic radar chart with 5 categories and one observation (you choose the values).
  15. Display a heatmap using imshow for a 10×10 matrix of random values; add a colorbar.
  16. Plot contour lines (contour) of z = sin(x)·cos(y) on a grid x,y ∈ [−3,3].
  17. Plot filled contours (contourf) for the same function with at least 15 levels.
  18. Create a 3D scatter plot (mplot3d) of 200 points sampled from a 3D normal distribution.
  19. Create a 3D wireframe plot for z = sin(√(x²+y²)) on a meshgrid over [−4,4].
  20. Create a 3D surface plot for z = x·e^(−x²−y²) with a colormap and colorbar.

Intermediate Questions

  1. Plot a histogram with bin edges you define explicitly (e.g., edges at 0,2,4,…,20) and show counts as text above bars.
  2. Compare distributions by plotting: histogram (density=True) and KDE curve on the same axes for 500 samples.
  3. Create a stacked histogram of two datasets (e.g., N(0,1) and N(2,1)) with 25 bins.
  4. Plot horizontal boxplots for three groups; customize notch, showmeans, and set different colors.
  5. Make a violin plot and overlay the group medians as points; ensure shared x for 4 groups.
  6. Build a stem plot of a noisy sine wave (20 points) and customize markerfmt and linefmt.
  7. Plot error bars with asymmetric errors (yerr as [lower, upper]) for 6 data points.
  8. Create a pie chart with one slice “exploded” and start angle set to 90°; ensure labels don’t overlap.
  9. Build a donut chart that also displays absolute values in the center as a summary text.
  10. Plot a polar bar chart (θ equally spaced for 12 months, r as monthly values you choose).
  11. Construct a radar chart with 6 categories for two different students and include a legend.
  12. Create a heatmap (imshow) of a correlation matrix (5×5) computed from random data; add tick labels.
  13. Plot contour and contourf of a bivariate Gaussian; add labeled contour lines (clabel).
  14. Create a heatmap with a diverging colormap and center at 0 using Normalize or TwoSlopeNorm.
  15. Plot a 3D scatter where point colors represent z-value and sizes represent distance from origin.
  16. Plot a 3D wireframe and surface of the same function in two subplots; share the colorbar where applicable.
  17. Create a 3D surface with custom stride (rstride, cstride) and add a contourf projection on the z=plane.
  18. Plot a filled contour (contourf) overlaid with a few contour lines and add a legend for the line levels.
  19. Generate a hexbin density plot alternative (if allowed) or simulate via 2D histogram heatmap with imshow.
  20. Create a small multi-panel figure: (a) histogram, (b) KDE, (c) boxplot, (d) violin of the same dataset for comparison.

Advanced Questions

  1. Build a full distribution dashboard for two datasets: panel A—hist+KDE overlay; panel B—boxplot; panel C—violin; panel D—stem (discrete sample). Use consistent titles and shared styling.
  2. Implement outlier analysis: create a boxplot for a dataset with injected outliers, then mark outliers on a separate violin plot and compare spread.
  3. Create a multi-category radar chart for 5 metrics across 3 teams; normalize values to [0,1], add gridlines, and a legend outside the plot.
  4. Design an informative donut chart for budget allocation with an inner ring (categories) and an outer ring (sub-categories) using two concentric pies; add total in the center.
  5. Produce a polar plot showing a rose curve r = cos(kθ) for k=2,3,4 in subplots; annotate maxima and include a shared super-title.
  6. Create a high-resolution heatmap for a custom function f(x,y) with imshow, add a secondary inset that zooms into a hotspot, and sync color scales.
  7. Combine contourf with quiver-like direction cues (or arrows drawn manually) to illustrate gradient directions on a surface; include a legend for levels.
  8. Build a 3D visualization suite for z = sin(x)·sin(y): subplot 1—surface with shading; subplot 2—wireframe; subplot 3—3D scatter of sampled points; consistent view angles.
  9. Create a 3D surface where colors encode another metric (e.g., curvature or |gradient|); add an accompanying colorbar and descriptive axis labels.
  10. Develop a publication-ready figure comparing two 2D density representations: (i) contour/contourf, (ii) heatmap (imshow); include matching color limits, labeled levels, and a succinct caption area rendered as figure text.