Using python 2.7x, cannot upgrade as I'm on a managed windows system. I'm trying to follow this example to merge subplots but return the following error:
'AxesSubplot' object has no attribute 'get_gridspec'
I've taken a look at other examples on here, but cannot find any that work with the build I'm using (Anaconda 2.7, Spyder IDE) Example from:
https://matplotlib.org/tutorials/intermediate/gridspec.html
fig9 = plt.figure(constrained_layout=False)
gs1 = fig9.add_gridspec(nrows=3, ncols=3, left=0.05, right=0.48,
wspace=0.05)
f9_ax1 = fig9.add_subplot(gs1[:-1, :])
f9_ax2 = fig9.add_subplot(gs1[-1, :-1])
f9_ax3 = fig9.add_subplot(gs1[-1, -1])
gs2 = fig9.add_gridspec(nrows=3, ncols=3, left=0.55, right=0.98,
hspace=0.05)
f9_ax4 = fig9.add_subplot(gs2[:, :-1])
f9_ax5 = fig9.add_subplot(gs2[:-1, -1])
f9_ax6 = fig9.add_subplot(gs2[-1, -1])
Looking at the documentation figure.add_gridspec
was added in matplotlib 3 and above.
For Python 3.5 and above you can simply update matplotlib to the latest version and the example will work. However, matplotlib 3 is not available for Python 2.7 or Python 3.4 and below.
Therefore you can use the old way as described in the old documentation
import matplotlib.gridspec as gridspec
gs1 = gridspec.GridSpec(3, 3)
gs1.update(left=0.05, right=0.48, wspace=0.05)
ax1 = plt.subplot(gs1[:-1, :])
ax2 = plt.subplot(gs1[-1, :-1])
ax3 = plt.subplot(gs1[-1, -1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With