Overview
Matplotlib 3.5, released on November 17, 2021, improves figure and axes creation with a more coherent API and new options.
Main Features
Improved figure creation
The subplot_mosaic() function is stabilized, allowing complex axes layouts with an intuitive text-based syntax.
python
import matplotlib.pyplot as plt
import numpy as np
# Intuitive mosaic layout
fig, axes = plt.subplot_mosaic(
[['top', 'top'],
['bottom_l', 'bottom_r']],
figsize=(10, 6),
)
x = np.linspace(0, 10, 100)
axes['top'].plot(x, np.sin(x))
axes['top'].set_title('Full signal')
axes['bottom_l'].bar([1, 2, 3], [4, 5, 6])
axes['bottom_r'].scatter(np.random.randn(50), np.random.randn(50))
# plt.show()
Axes improvements
Axes benefit from improved automatic legend positioning and label rendering enhancements.
python
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(8, 5))
x = np.linspace(0, 2 * np.pi, 100)
ax.plot(x, np.sin(x), label='sin(x)')
ax.plot(x, np.cos(x), label='cos(x)')
ax.plot(x, np.sin(x) + np.cos(x), label='sin+cos')
# Legend with improved automatic placement
ax.legend(loc='best')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('Trigonometric functions')
# plt.show()
