How to suppress “Using categorical units to plot a list of strings that are all parsable as floats or dates.”

Tags:

If log level is set to INFO, “Using categorical units to plot a list of strings that are all parsable as floats or dates. If these strings should be plotted as numbers, cast to the appropriate data type before plotting.” may be observed when it’s not really relevant.

Here’s how to suppress it.

def init_logging():
    class SuppressMatplotlibInfo(logging.Filter):
        def filter(self, record):
            return (
                "Using categorical units to plot a list of strings that are all parsable as floats or dates. If these strings should be plotted as numbers, cast to the appropriate data type before plotting."
                != record.getMessage()
            )

    logging.basicConfig(level=logging.INFO)
    matplotlib_logger = logging.getLogger("matplotlib.category")
    matplotlib_logger.addFilter(SuppressMatplotlibInfo())