1 Hour

2. Customizing Plots

Figure Dimensions and Labels

To define the size of your plot, use the figsize parameter within plt.figure. Setting appropriate dimensions ensures your data remains readable. Once the figure is initialized, you can add descriptive context using plt.title, plt.xlabel, and plt.ylabel to ensure your visual narrative is clear to the audience.

Operator Note: Always specify the figsize as a tuple (width, height) in inches.
Python 3
import matplotlib.pyplot as plt

plt.figure(figsize=(8, 4))
plt.plot([1, 2, 3], [1, 4, 9])
plt.title('Growth Analysis')
plt.xlabel('Time')
plt.ylabel('Value')
plt.show()

Styling Elements and Gridlines

Visual aesthetic is controlled through arguments like color, marker, and linestyle. To add a reference framework, plt.grid is essential. Passing True to this function toggles the grid, allowing viewers to trace data points to their axes more effectively.

Common marker types include o for circles and s for squares, while line styles can be adjusted using dashes like -- or ':'.

Operator Note: Use linestyle with -- for a dashed look that helps distinguish multiple series.
Python 3
import matplotlib.pyplot as plt

plt.plot([1, 2, 3], [1, 4, 9], color='red', marker='o', linestyle='--')
plt.grid(True)
plt.show()

Knowledge Check

Ready to test your understanding of 2. Customizing Plots?

Back