def clean_plot(fig,ax,x_remove=['top'],y_remove=['right']):

    """ clean matplotlib plot
    
    parameters:
    ==========
    
    fig: matplotlib figure
    ax: matplotlib ax
    x_remove: the x axes that you want to remove ( either top or bottom)
    y_remove: the y axes that you want to remove (either rigth or left)
    
    
    returns:
    =======
    
    fig,ax 
    
    """
    
    x_keep = ['bottom','top']
    y_keep = ['left','right']
    
    
    
    for x_r in x_remove:
         x_keep.remove(x_r)
         
    for y_r in y_remove:
         y_keep.remove(y_r)
         
    try:
        for a in ax.flatten():
            
            for r in x_remove+y_remove:
                a.spines[r].set_visible(False)
            
            for k in x_keep:
                a.xaxis.set_ticks_position(k)
                
            for k in y_keep:
                a.yaxis.set_ticks_position(k)	
                
            a.tick_params(direction='out')
            
        return fig,ax
        
    except:
    
        for r in x_remove+y_remove:
            ax.spines[r].set_visible(False)
        
        for k in x_keep:
            ax.xaxis.set_ticks_position(k)
            
        for k in y_keep:
            ax.yaxis.set_ticks_position(k)
        
        ax.tick_params(direction='out')
        return fig,ax