Skip to content
Advertisement

Python highlight user chosen area in contourf plot

What is the best solution for highlighting an area in a contourf plot? I want the background to be opacity of 0.5 and the user chosen area to be normal. How can I achieve this?

Advertisement

Answer

In How to nicely plot clipped layered artists in matplotlib? Jake Vanderplas shows a way to draw a rectangle with a rectangular hole. The code can be adapted for your situation. The following example starts from a tutorial example, and highlights the third contour:

JavaScript

Instead of darkening the outside region, it could also be hatched (similar to the linked post). This would set the edge color of the mask to ‘black’, and create the full rectangle with hatching.

JavaScript

plt.contourf with one highlighted area

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement