plt.plot: A convenient way to create figures and axes implicitly for quick and simple plots.
fig, ax = plt.subplots(): Provides explicit control over figures and axes, ideal for complex and customized visualizations.
2024
plt.plot: A convenient way to create figures and axes implicitly for quick and simple plots.
fig, ax = plt.subplots(): Provides explicit control over figures and axes, ideal for complex and customized visualizations.
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.xticks([1, 2, 3], ['One', 'Two', 'Three']) plt.yticks([4, 5, 6], ['Four', 'Five', 'Six']) plt.show()
fig, ax = plt.subplots() ax.plot([1, 2, 3], [4, 5, 6]) ax.set_xticks([1, 2, 3]) ax.set_xticklabels(['One', 'Two', 'Three']) ax.set_yticks([4, 5, 6]) ax.set_yticklabels(['Four', 'Five', 'Six']) plt.show()
Scope of Impact: plt-level functions affect the current or most recent figure or axes, while ax-level methods target specific axes objects.
Control: ax-level provides more precise control for customizing plots, especially when working with multiple subplots.
No practice exercises here.
Just wanted to clarify some of the different syntax we have seen along the way.