MatplotLib Assignment– 7

Interactivity & Extensions

Basic Questions

  1. Create a sine line plot with a Slider to control frequency (1–10) and update the curve in real time.
  2. Add a Slider to control line amplitude for the same sine plot.
  3. Add a Button labeled “Reset” that resets both sliders from Q1–Q2 to default values.
  4. Create a plot with CheckButtons to toggle visibility of three lines: sin, cos, tan (limit tan y-range).
  5. Build a plot with RadioButtons to switch line styles among -, –, : for a single curve.
  6. Implement a RangeSlider to limit the visible x-interval of a timeseries (update x-limits interactively).
  7. Add a TextBox widget to accept a title string and update the figure title on submit.
  8. Make a scatter plot where clicking a point (pick event) highlights it by increasing marker size and changing color.
  9. Register a button_press_event that prints (or annotates) the clicked data coordinates on the axes.
  10. Register a motion_notify_event that shows a live tooltip of (x, y) near the cursor for a dense line.
  11. Register a key_press_event to toggle grid visibility by pressing the g key.
  12. Use Pandas: read or construct a small DataFrame and plot DataFrame.plot(); add Matplotlib legend title.
  13. Use Seaborn to draw a histogram (or histplot) from a NumPy array on Matplotlib axes; add Matplotlib title/labels.
  14. Create a simple Plotly line chart from the same data used in a Matplotlib plot for comparison (two separate figures).
  15. Export a Matplotlib figure to SVG and PNG with dpi=300.
  16. Export a Matplotlib figure to PDF with embedded fonts; verify file size difference vs PNG.
  17. Enable LaTeX math rendering (either text.usetex=True or PGF backend) and render a title with $\\int_0^{\\pi} \\sin(x)\\,dx=2$.
  18. Save a figure using the PGF backend suitable for LaTeX inclusion (.pgf file).
  19. Embed a Matplotlib figure in a minimal Tkinter app window using FigureCanvasTkAgg.
  20. Embed a Matplotlib figure in a minimal PyQt (PyQt5/PySide6) app using FigureCanvasQTAgg.

Intermediate Questions

  1. Build two synchronized axes: a main line plot and an inset zoom; add a Slider that moves the inset window across x.
  2. Create a scatter with a CheckButtons panel to toggle three clusters on/off; update a shared legend dynamically.
  3. Add two Sliders to a polynomial curve to control coefficients a and b in ax^2 + bx + c; update text of fitted vertex.
  4. Implement a Button “Randomize” that regenerates scatter data and updates a KDE curve (via Seaborn) overlaid on the same axes.
  5. Create a plot where a pick_event on a line toggles a persistent annotation labeling that vertex; clicking again removes it.
  6. Use mpl_connect to implement rubber-band zoom: on mouse drag, draw a rectangle; on release, set new x/y-limits.
  7. Construct a brushing-and-linking demo: select a rectangle on subplot A (scatter), highlight matching points on subplot B (hist).
  8. With Pandas, build a small dashboard: top—time series; bottom—rolling mean and rolling std; add a RangeSlider to set date window.
  9. Style the figure with a Seaborn theme (e.g., sns.set_theme()); plot a Pandas boxplot; add Matplotlib annotations for outliers.
  10. Create a Matplotlib plot and a Plotly equivalent; export the Matplotlib figure to SVG and the Plotly figure to HTML, saving both.
  11. Use key_press_event to implement ‘n’ = next dataset, ‘p’ = previous dataset cycling through 5 arrays in a single axes.
  12. Draw a scatter with pick_event and display a floating annotation that follows the mouse until click elsewhere (hide on ESC).
  13. Build a Tkinter GUI with two buttons: “Add Noise” (mutates data) and “Smooth” (applies moving average) updating the embedded plot.
  14. Build a PyQt GUI with a dropdown to choose plot type (line, scatter, bar) for the same dataset; update axes accordingly.
  15. Export a figure for LaTeX using PGF; ensure fonts use \\usepackage{mathpazo} and verify serif fonts in the plot.
  16. Generate a multiplot PDF report: four pages saved via PdfPages—(i) summary, (ii) line, (iii) box, (iv) scatter with regression line.
  17. Implement interactive checkboxes to toggle major/minor grids and tick directions; changes apply instantly.
  18. Combine Seaborn heatmap on Matplotlib axes with a Matplotlib colorbar; add a Button to switch colormaps.
  19. Use mplcursors (if available) or custom events to create hover tooltips on a dense scatter; fall back to annotate on hover.
  20. Export two formats of the same styled figure (SVG & PDF) and programmatically check (print) file sizes for QA logging.

Advanced Questions

  1. Interactive Model Explorer: Create a three-panel figure (loss, accuracy, confusion matrix). Add sliders for learning rate and epochs that regenerate synthetic results; include a reset button and style toggle (Seaborn vs default).
  2. Linked Dashboards: Two subplots—A: time series; B: frequency spectrum. Implement brushing in A that recomputes and updates the spectrum in B for the selected window.
  3. Event Routing Framework: Build a small event manager that registers multiple callbacks (key_press, button_press, motion) and logs actions in a side text box; ensure clean connect/disconnect.
  4. Seaborn × Matplotlib Fusion: Compose a categorical plot grid via Seaborn (e.g., catplot) but attach Matplotlib widgets (Slider/Buttons) to filter categories and redraw.
  5. Matplotlib ↔ Plotly Interop: Create a function that renders the same dataset as either (a) Matplotlib static PDF for print, or (b) Plotly interactive HTML for web, chosen by a radio widget. Save outputs.
  6. LaTeX Report Pipeline: Configure PGF backend and produce figures with consistent serif fonts, math labels, and tight_layout; compile a multi-page PDF report via PdfPages with captions as figure text.
  7. GUI Mini-App (Tkinter): Build a 2-tab interface: Tab 1—data loader & preview; Tab 2—plot configurator (type, color, markers) with a live Matplotlib canvas and export buttons (PNG, SVG, PDF, PGF).
  8. GUI Mini-App (PyQt): Build an app with a left control panel (checkboxes, sliders, combo boxes) and right plot canvas; support zoom, pan, and a status bar showing data coordinates; add “Export to PDF/SVG”.
  9. High-Performance Picking: For 100k-point scatter, implement efficient picking using collections and a downsampled index; on pick, highlight all nearby points within a radius; show latency metrics.
  10. Interactive Report Builder: Build a script that generates: (i) styled Matplotlib figures, (ii) exports in PNG, SVG, PDF, PGF, and (iii) assembles a simple LaTeX .tex snippet with \\includegraphics{} entries referencing the generated files.