Instagram
youtube
Facebook
Twitter

Set Figure Size and Resolution

Description:
This program shows how to set a custom figure size (width × height) and resolution (DPI) for better control over the chart layout and image clarity.



Code Explanation:

  • autopct='%1.1f%%' shows percentage on each pie slice.

  • Helps show proportion of each part in total.

  • Each slice represents a category with a portion of the whole.

  • labels and colors add clarity and visual appeal.


Program:

import matplotlib.pyplot as plt

# Set figure size (width=8 inches, height=5 inches) and resolution (dpi=100)
plt.figure(figsize=(8, 5), dpi=100)

# Sample data
x = ['A', 'B', 'C', 'D']
y = [10, 20, 15, 25]

# Create a bar chart
plt.bar(x, y, color='orange')

# Add title and labels
plt.title('Bar Chart with Custom Size and Resolution')
plt.xlabel('Category')
plt.ylabel('Values')

# Show grid and chart
plt.grid(True, axis='y')
plt.show()



Output: