Add blur to patch outline in matplotlib?

Viewed 342

I am plotting a regular patch in matplotlib, defining an area. However, there is uncertainty around the edges of this area. i would like to add 'blur'.

By brute-forcing it I did it one way - sliced the shape along the x-direction and constructed segments of sub-patches, each with their custom facealpha. I could do this by slicing in 2D and then adjusting facealpha with a more convoluted algorithm.

Any simpler ideas?

enter image description here enter image description here

1 Answers

I'm not aware of any simple way to do this directly. Matplotlib can do things like drop shadows but that won't give you blur. However, matplotlib's Agg renderer has support for custom filters. You can see examples here.

Specifically, you might be able to do something with the GaussianFilter example. Here I think it's being used to generate the blurred drop shadows but you could figure out how to get it to do what you want in your case. Note that what you are doing in these cases is manually defining a process_image() which works directly on image data.

You may also want to look at this question regarding plotting blurred points.

Related