Matplotlib Assignment– 2
Figure & Axes Mastery
Basic Questions
- Create an empty figure using plt.figure() and display it.
- Create a figure with size 8×6 inches using plt.figure(figsize=(8,6)).
- Create a figure with DPI set to 150 and plot a line inside it.
- Use plt.subplots() to create one figure with a single axes and plot y=x.
- Create a figure with two subplots (1 row, 2 columns) showing y=x and y=x².
- Create a figure with two subplots (2 rows, 1 column) showing sine and cosine curves.
- Plot a line chart in a figure where the background color of the figure is light gray.
- Create a figure with 3 subplots using add_subplot() method.
- Create a figure and plot 4 subplots in a 2×2 grid using plt.subplots().
- Create a line chart and set the figure aspect ratio to be square (1:1).
- Create a line chart and change its aspect ratio to 16:9.
- Use tight_layout() to avoid overlapping labels in a 2×2 subplot figure.
- Use constrained_layout=True in plt.subplots() and compare with tight_layout().
- Plot two lines on two subplots and adjust the spacing with tight_layout().
- Create a figure with customized title “Figure & Axes Demo” using fig.suptitle().
- Create a figure with subplot titles for each axes using set_title().
- Plot a line chart and save the figure as output.png using savefig().
- Save the same figure as output.jpg with DPI=300.
- Save the same figure as a PDF file.
- Save a scatter plot as a transparent PNG file.
Intermediate Questions
- Create a figure with 2×2 grid using add_subplot() and plot different functions in each.
- Create a figure with 1 row and 3 columns of subplots using plt.subplots().
- Create a subplot grid of 3×3 but only fill 5 plots with different graphs.
- Use GridSpec to create a figure with one large plot on top and two small plots below.
- Create a GridSpec layout where one plot spans two columns and one smaller plot is below it.
- Create a subplot layout with unequal subplot sizes using GridSpec.
- Create a figure with DPI=200 and plot sine and cosine functions with labels.
- Create a wide figure (12×4 inches) showing 3 line plots side by side.
- Create a tall figure (6×12 inches) with 2 subplots stacked vertically.
- Plot 4 subplots and adjust spacing manually using fig.subplots_adjust().
- Create 4 subplots and remove space between them using wspace=0 and hspace=0.
- Create a multi-axes figure and set different aspect ratios for each subplot.
- Create a 2×2 subplot figure and demonstrate the difference between tight_layout() and no layout adjustment.
- Create a 2×2 subplot figure and demonstrate the difference between tight_layout() and constrained_layout.
- Create a figure with 6 subplots and adjust the layout using fig.tight_layout(pad=2).
- Save a figure as a PNG with resolution 200 DPI and compare with 50 DPI visually.
- Save a figure as a JPEG with quality set to 95%.
- Save a figure in both PNG and PDF formats for publication.
- Save a multi-subplot figure as an SVG format and open it in a browser.
- Save a figure with transparent background and overlay it on another image.
Advanced Questions
- Create a 3×3 subplot layout using GridSpec where the center plot spans 2 rows and 2 columns.
- Create a dashboard-like figure: one wide plot on top and three smaller plots below using GridSpec.
- Create a figure where one subplot shows a histogram, another a scatter, another a bar chart, and arrange them using custom GridSpec.
- Create a professional-quality figure with aspect ratio 16:9, DPI=300, labeled axes, grid, and legend, and save it as both PDF and PNG.
- Create a figure with constrained_layout enabled and annotate each subplot with its index (e.g., “Subplot 1”).
- Create a figure with 6 subplots and add a common x-axis label and common y-axis label.
- Create a complex GridSpec figure where some subplots are merged to show larger visualizations.
- Create a figure showing multiple sine waves on different subplots and save it in four different formats (PNG, JPG, PDF, SVG).
- Create a publication-ready figure with exact figure size (10×6 inches), resolution (DPI=300), and font sizes optimized for research papers.
- Create a professional visualization where figure size, aspect ratio, layout, and resolution are all customized, and save it as a transparent PNG for presentation slides.