def _get_dpi_ratio(fig):
    """Get DPI ratio (to handle hi-DPI screens)."""
    dpi_ratio = 1.0
    for key in ('_dpi_ratio', '_device_scale'):
        dpi_ratio = getattr(fig.canvas, key, dpi_ratio)
    return dpi_ratio
