MatplotLib Assignment– 4
Advanced Plot Types
Basic Questions
- Plot a histogram of 200 random integers between 1 and 10 with 10 bins; show frequency on y-axis.
- Plot a normalized histogram (density=True) of 500 values drawn from a normal distribution (μ=0, σ=1).
- Overlay two histograms (normal vs. uniform, 500 samples each) with transparency to compare distributions.
- Create a simple density line by plotting the normalized histogram (as step) of normal data with 30 bins.
- Plot a KDE curve for 300 normal samples (use scipy.stats.gaussian_kde if available; otherwise skip).
- Draw a boxplot of exam scores for 1 class (list of 25 values you define or randomly generate).
- Draw side-by-side boxplots comparing two classes (Class A vs Class B, 25 scores each).
- Plot a violin plot for three groups (A, B, C) with 50 samples each from different normal means.
- Create a stem plot for the discrete sequence y = [3, 1, 4, 1, 5, 9, 2].
- Plot a line with error bars (means = [5,7,6,8], std = [0.5,1.0,0.3,0.8]) using plt.errorbar.
- Create a pie chart of market share for 5 brands with labels and percentage autopct.
- Create a donut chart (pie with a white circle in the center) for the same market share data.
- Plot a polar line chart for r = 1 + 0.5*cos(θ) where θ ∈ [0, 2π].
- Create a basic radar chart with 5 categories and one observation (you choose the values).
- Display a heatmap using imshow for a 10×10 matrix of random values; add a colorbar.
- Plot contour lines (contour) of z = sin(x)·cos(y) on a grid x,y ∈ [−3,3].
- Plot filled contours (contourf) for the same function with at least 15 levels.
- Create a 3D scatter plot (mplot3d) of 200 points sampled from a 3D normal distribution.
- Create a 3D wireframe plot for z = sin(√(x²+y²)) on a meshgrid over [−4,4].
- Create a 3D surface plot for z = x·e^(−x²−y²) with a colormap and colorbar.
Intermediate Questions
- Plot a histogram with bin edges you define explicitly (e.g., edges at 0,2,4,…,20) and show counts as text above bars.
- Compare distributions by plotting: histogram (density=True) and KDE curve on the same axes for 500 samples.
- Create a stacked histogram of two datasets (e.g., N(0,1) and N(2,1)) with 25 bins.
- Plot horizontal boxplots for three groups; customize notch, showmeans, and set different colors.
- Make a violin plot and overlay the group medians as points; ensure shared x for 4 groups.
- Build a stem plot of a noisy sine wave (20 points) and customize markerfmt and linefmt.
- Plot error bars with asymmetric errors (yerr as [lower, upper]) for 6 data points.
- Create a pie chart with one slice “exploded” and start angle set to 90°; ensure labels don’t overlap.
- Build a donut chart that also displays absolute values in the center as a summary text.
- Plot a polar bar chart (θ equally spaced for 12 months, r as monthly values you choose).
- Construct a radar chart with 6 categories for two different students and include a legend.
- Create a heatmap (imshow) of a correlation matrix (5×5) computed from random data; add tick labels.
- Plot contour and contourf of a bivariate Gaussian; add labeled contour lines (clabel).
- Create a heatmap with a diverging colormap and center at 0 using Normalize or TwoSlopeNorm.
- Plot a 3D scatter where point colors represent z-value and sizes represent distance from origin.
- Plot a 3D wireframe and surface of the same function in two subplots; share the colorbar where applicable.
- Create a 3D surface with custom stride (rstride, cstride) and add a contourf projection on the z=plane.
- Plot a filled contour (contourf) overlaid with a few contour lines and add a legend for the line levels.
- Generate a hexbin density plot alternative (if allowed) or simulate via 2D histogram heatmap with imshow.
- Create a small multi-panel figure: (a) histogram, (b) KDE, (c) boxplot, (d) violin of the same dataset for comparison.
Advanced Questions
- 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.
- Implement outlier analysis: create a boxplot for a dataset with injected outliers, then mark outliers on a separate violin plot and compare spread.
- 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.
- 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.
- 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.
- 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.
- Combine contourf with quiver-like direction cues (or arrows drawn manually) to illustrate gradient directions on a surface; include a legend for levels.
- 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.
- Create a 3D surface where colors encode another metric (e.g., curvature or |gradient|); add an accompanying colorbar and descriptive axis labels.
- 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.