Code does not work on new version of Matplotlib (original) (raw)
Hello everyone,
I would need a little help on this code that works with matplotlib 3.3.2 but not with matplotlib 3.9.2.
X1 and Y1 are numpy.ndarray
contour=True
plt.figure(figname, figsize=(6,6), dpi=100)
ax = plt.gca()
ax.scatter(X1[::n1], Y1[::n1], marker='.', alpha=0.1, label='XY')
if contour:
sns.kdeplot(x=X1[::30], y=Y1[::30], color='k', levels=levels, alpha=0.3, ax=ax, linestyles="--")
contourdata=[]
for i,c in enumerate(ax.collections):
if isinstance(c, matplotlib.collections.LineCollection):
if len(c.get_segments())>0:
v = c.get_segments()[0]
cv=centeroidnp(v)
ax.plot(list(zip(*v))[0], list(zip(*v))[1], color='k', alpha=0.3, label="Outer Contour", linewidth=2.0)
ax.scatter(cv[0], cv[1], color='k', alpha=0.3, label="Contour center")
contourdata.append((i, len(v), cv))
break
I have two problems:
- isinstance(c, matplotlib.collections.LineCollection) always returns False
- c.get_segments returns an error: ‘QuadContourSet’ object has no attribute ‘get_segments’
What should I do to make it work with the 3.9.2 version of Matplotlib?
Thank you very much for your help
MRAB (Matthew Barnett) May 6, 2025, 4:17pm 2
For Matplotlib-related problems, I’d recommend you visit the Matplotlib forum where there’s this post:
Collections attribute deprecation in version > 3.8 - Community - Matplotlib