Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Matplotlib Patches and Contour Plots

Is there a way to make the filling of a circle transparent when using the PatchCollection? I plotted a circle, and I tried setting the facecolor to 'none', but it is covering the contour map that it is plotted on top of. I would like to see the outline of the circle with the contouring remaining visible behind it.

The stereonet was plotted using the mplstereonet-0.2 third-party software. Here is the part of the script where the image is plotted:

hold(True)



fig, ax = plt.subplots(subplot_kw = dict(projection = 'stereonet')) # Schmidt by default

cax = ax.density_contourf(strike, dip, measurement = 'poles')

ax.pole(strike, dip, 'k^', markersize = 3)
ax.grid(True)


patches = []
circle = Circle((0, 0), 0.5, facecolor = 'none', fill = False)
patches.append(circle)
p = PatchCollection(patches)
ax.add_collection(p)

cbar = fig.colorbar(cax, cmap = cm)
cbar.set_clim(0, 25)

enter image description here

like image 483
user1620716 Avatar asked Jun 09 '26 09:06

user1620716


1 Answers

I solved the problem, but thank you to anyone that was possibly looking into this.

The solution:

    p = PatchCollection(patches, match_original = True)

This will make it so that the contour is seen behind the shape.

enter image description here

like image 78
user1620716 Avatar answered Jun 10 '26 23:06

user1620716



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!