(fig=None,
            ax=None,
            top=True,
            right=True,
            left=False,
            bottom=False,
            offset=None,
            trim=False)
Remove the top and right spines from plot(s).
    Parameters
    ----------

    fig : matplotlib figure, optional
        Figure to despine all axes of, default uses current figure.
    ax : matplotlib axes, optional
        Specific axes object to despine.
    top, right, left, bottom : boolean, optional
        If True, remove that spine.
    offset : int or dict, optional
        Absolute distance, in points, spines should be moved away
        from the axes (negative values move spines inward). A single value
        applies to all spines; a dict can be used to set offset values per
        side.
    trim : bool, optional
        If True, limit spines to the smallest and largest major tick
        on each non-despined axis.

    Returns
    -------
    None

    License
    -------
    MIT

    This is borrowed from here: https://github.com/mwaskom/seaborn/blob/0beede57152ce80ce1d4ef5d0c0f1cb61d118375/seaborn/utils.py#L184
Remove the top and right spines from plot(s).
    Parameters
    ----------
Remove the top and right spines from plot ( s ) . Parameters ----------
def despine(fig=None,
            ax=None,
            top=True,
            right=True,
            left=False,
            bottom=False,
            offset=None,
            trim=False):
    """Remove the top and right spines from plot(s).
    Parameters
    ----------

    fig : matplotlib figure, optional
        Figure to despine all axes of, default uses current figure.
    ax : matplotlib axes, optional
        Specific axes object to despine.
    top, right, left, bottom : boolean, optional
        If True, remove that spine.
    offset : int or dict, optional
        Absolute distance, in points, spines should be moved away
        from the axes (negative values move spines inward). A single value
        applies to all spines; a dict can be used to set offset values per
        side.
    trim : bool, optional
        If True, limit spines to the smallest and largest major tick
        on each non-despined axis.

    Returns
    -------
    None

    License
    -------
    MIT

    This is borrowed from here: https://github.com/mwaskom/seaborn/blob/0beede57152ce80ce1d4ef5d0c0f1cb61d118375/seaborn/utils.py#L184
     """
    # Get references to the axes we want
    if fig is None and ax is None:
        axes = plt.gcf().axes
    elif fig is not None:
        axes = fig.axes
    elif ax is not None:
        axes = [ax]

    for ax_i in axes:
        for side in ["top", "right", "left", "bottom"]:
            # Toggle the spine objects
            is_visible = not locals()[side]
            ax_i.spines[side].set_visible(is_visible)
            if offset is not None and is_visible:
                try:
                    val = offset.get(side, 0)
                except AttributeError:
                    val = offset
                _set_spine_position(ax_i.spines[side], ('outward', val))

        # Set the ticks appropriately
        if bottom:
            ax_i.xaxis.tick_top()
        if top:
            ax_i.xaxis.tick_bottom()
        if left:
            ax_i.yaxis.tick_right()
        if right:
            ax_i.yaxis.tick_left()

        if trim:
            # clip off the parts of the spines that extend past major ticks
            xticks = ax_i.get_xticks()
            if xticks.size:
                firsttick = np.compress(xticks >= min(ax_i.get_xlim()),
                                        xticks)[0]
                lasttick = np.compress(xticks <= max(ax_i.get_xlim()),
                                       xticks)[-1]
                ax_i.spines['bottom'].set_bounds(firsttick, lasttick)
                ax_i.spines['top'].set_bounds(firsttick, lasttick)
                newticks = xticks.compress(xticks <= lasttick)
                newticks = newticks.compress(newticks >= firsttick)
                ax_i.set_xticks(newticks)

            yticks = ax_i.get_yticks()
            if yticks.size:
                firsttick = np.compress(yticks >= min(ax_i.get_ylim()),
                                        yticks)[0]
                lasttick = np.compress(yticks <= max(ax_i.get_ylim()),
                                       yticks)[-1]
                ax_i.spines['left'].set_bounds(firsttick, lasttick)
                ax_i.spines['right'].set_bounds(firsttick, lasttick)
                newticks = yticks.compress(yticks <= lasttick)
                newticks = newticks.compress(newticks >= firsttick)
                ax_i.set_yticks(newticks)
def despine ( fig = None , ax = None , top = True , right = True , left = False , bottom = False , offset = None , trim = False ) : # Get references to the axes we want if fig is None and ax is None : axes = plt . gcf ( ) . axes elif fig is not None : axes = fig . axes elif ax is not None : axes = [ ax ] for ax_i in axes : for side in [ "top" , "right" , "left" , "bottom" ] : # Toggle the spine objects is_visible = not locals ( ) [ side ] ax_i . spines [ side ] . set_visible ( is_visible ) if offset is not None and is_visible : try : val = offset . get ( side , 0 ) except AttributeError : val = offset _set_spine_position ( ax_i . spines [ side ] , ( 'outward' , val ) ) # Set the ticks appropriately if bottom : ax_i . xaxis . tick_top ( ) if top : ax_i . xaxis . tick_bottom ( ) if left : ax_i . yaxis . tick_right ( ) if right : ax_i . yaxis . tick_left ( ) if trim : # clip off the parts of the spines that extend past major ticks xticks = ax_i . get_xticks ( ) if xticks . size : firsttick = np . compress ( xticks >= min ( ax_i . get_xlim ( ) ) , xticks ) [ 0 ] lasttick = np . compress ( xticks <= max ( ax_i . get_xlim ( ) ) , xticks ) [ - 1 ] ax_i . spines [ 'bottom' ] . set_bounds ( firsttick , lasttick ) ax_i . spines [ 'top' ] . set_bounds ( firsttick , lasttick ) newticks = xticks . compress ( xticks <= lasttick ) newticks = newticks . compress ( newticks >= firsttick ) ax_i . set_xticks ( newticks ) yticks = ax_i . get_yticks ( ) if yticks . size : firsttick = np . compress ( yticks >= min ( ax_i . get_ylim ( ) ) , yticks ) [ 0 ] lasttick = np . compress ( yticks <= max ( ax_i . get_ylim ( ) ) , yticks ) [ - 1 ] ax_i . spines [ 'left' ] . set_bounds ( firsttick , lasttick ) ax_i . spines [ 'right' ] . set_bounds ( firsttick , lasttick ) newticks = yticks . compress ( yticks <= lasttick ) newticks = newticks . compress ( newticks >= firsttick ) ax_i . set_yticks ( newticks )