Tuesday, January 14, 2025
HomeProgrammingHow do I change the size of figures drawn with

How do I change the size of figures drawn with

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

See also  How to Use GCC to Compile C Code

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

See also  Java Initialize array

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.

See also  the Max Value of an Integer in Java

 

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x