3

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

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

3 Comments

I was just about to respond. My comment would be that if you only plot 1 circle, avoid the whole PatchColection and add it direcly with: ax.add_artist(circle)
Nice. I was going to suggest using ax.add_patch(circle) which works fine (if you only have one patch there's no need to use a PatchCollection). Though, you should have really provided a minimal working example in your question.
Just FYI, you can also specify facecolor='none' when creating the PatchCollection (or use p.set_facecolor). The reason that the default isn't to match the original patch when making a collection is that collections are commonly used to either speed up drawing of a bunch of almost identical artists or map some attribute such as facecolor to another scalar (e.g. color by z). (On another side note, I didn't even know the match_original option existed. That's handy!) As everyone else mentioned, for a single circle, just adding it directly is easier. Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.