I have a code (shown below as a minimal working example, MWE
) which produces a warning when plotting a colorbar:
/usr/local/lib/python2.7/dist-p
You probably don't want to catch this warning as an exception. That will interrupt the function call.
Use the warnings standard library module to control warnings.
You can suppress a warning from a specific function call using a context manager:
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
fig.tight_layout()
To ignore all warnings from matplotlib:
warnings.filterwarnings("ignore", module="matplotlib")
To ignore only UserWarnings from matplotlib:
warnings.filterwarnings("ignore", category=UserWarning, module="matplotlib")