import matplotlib.pyplot as plt from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas fig, ax = plt.subplots() ax.plot([1, 2, 3], [4, 5, 6]) canvas = FigureCanvas(fig) canvas.print_jpg('example.jpg')
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure fig = Figure() canvas = FigureCanvas(fig) ax = fig.add_subplot(111) ax.plot([1, 2, 3], [4, 5, 6]) canvas.print_png('example.png')This example creates a Figure object directly, rather than using pyplot, and then renders the plot as a PNG file using FigureCanvasAgg. Overall, the Matplotlib library provides a powerful set of tools for creating and rendering plots in Python, with the backend_agg package providing a flexible and easy-to-use renderer for exporting plots as image files.