import matplotlib.pyplot as plt # Create a new figure with a custom size fig = plt.figure(figsize=(10, 6)) # Add some data to the figure plt.plot([1, 2, 3, 4, 5], [1, 4, 9, 16, 25]) # Show the figure plt.show()
To change the size of a figure drawn with Matplotlib, you can use the figure() function and specify the figsize parameter. This parameter takes a tuple of (width, height) in inches, and sets the size of the figure accordingly.
In our example, we use the plt.figure() function to create a new figure with a custom size of (10, 6) inches. Then, we add some data to the figure using the plt.plot() function, and show the figure using the plt.show() function. The resulting figure should have the specified size.Note that you can also use the figsize parameter with the subplots() function to create a figure with multiple subplots of a custom size. Here is an example:
import matplotlib.pyplot as plt # Create a figure with multiple subplots of a custom size fig, axs = plt.subplots(2, 2, figsize=(10, 6)) # Add some data to each subplot axs[0, 0].plot([1, 2, 3, 4,
Learn Flask development and learn to build cool apps with our premium Python course on Udemy.
Subscribe to be the first to know when a new Python course is released.