To change the size of figures drawn in Python, particularly using libraries like Matplotlib, you can adjust the figure size using the figsize parameter of the plt.figure() or plt.subplots() functions.
Here’s how to do it:
Example using plt.figure():
Python Copy code
import matplotlib.pyplot as plt
# Set the figure size (width, height) in inches
plt.figure(figsize=(10, 6))
# Plot something
plt.plot([1, 2, 3, 4], [10, 20, 25, 30])
# Add labels and title
plt.title(‘Example Plot’)
plt.xlabel(‘X-axis’)
plt.ylabel(‘Y-axis’)
# Show the plot
plt.show()
Example using plt.subplots():
Python Copy code
import matplotlib.pyplot as plt
# Create a figure and axes with specific size
fig, ax = plt.subplots(figsize=(8, 5))
# Plot something
ax.plot([1, 2, 3, 4], [10, 20, 25, 30])
# Add labels and title
ax.set_title(‘Example Plot’)
ax.set_xlabel(‘X-axis’)
ax.set_ylabel(‘Y-axis’)
# Show the plot
plt.show()
Notes:
The figsize parameter takes a tuple (width, height), where dimensions are specified in inches.
Increasing the figure size can make the plot more readable, especially for presentations or detailed visualizations.