Complete the code to create a simple line plot.
import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4], [10, 20, 25, 30]) plt.[1]()
The show() function displays the plot on the screen.
Complete the code to save the plot as a PNG file.
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.[1]('plot_image.png')
The savefig() function saves the current plot to a file.
Fix the error in saving the plot with high resolution.
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [3, 2, 1]) plt.savefig('high_res_plot.png', dpi=[1])
The dpi parameter expects an integer for resolution. 300 dpi is a common high-quality setting.
Fill both blanks to save a plot with a transparent background and tight layout.
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [3, 2, 1]) plt.savefig('transparent_plot.png', [1]=True, [2]='tight')
transparent=True makes the background see-through.bbox_inches='tight' trims extra whitespace around the plot.
Fill all three blanks to save a plot with a custom size, high dpi, and no axis.
import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=([1], [2])) ax.plot([1, 2, 3], [3, 2, 1]) ax.axis([3]) fig.savefig('custom_plot.png', dpi=300)
figsize=(8, 6) sets the plot size in inches.ax.axis('off') hides the axis lines and labels.
The plot is saved with 300 dpi for high quality.