Skip to content

[bug] Add a recovery function for the overwrite_axisgrid #63

@antecede

Description

@antecede

Great work, thanks for open source! It greatly facilitates the drawing needs of the academic community!
I have located a small bug during the use process. I hope you can handle it when you have time. I am very grateful!

After applying the overwrite_axisgrid function to override the default SNS settings, if you continue to plot and save with SNS, the problem shown in the following figure will occur, so it is best to add a function to restore the default SNS Grid settings.

example code
patchworklib-examples/seaborn_grid.ipynb

# Comment load_seaborngrid code
# g2 = pw.load_seaborngrid(g2) 
# Save the original Seaborn Grid Figure directly
g2.savefig("test.svg")

result
Image

Problematic code

def overwrite_axisgrid():
    """

    Overwrite `__init__` functions in seaborn.axisgrid.FacetGrid, 
    seaborn.axisgrid.PairGrid and seaborn.axisgrid.JointGrid.
    The function changes the figure object given in the `__init__` functions of the 
    axisgrid class objects, which is used for drawing plots, to `_basefigure 
    in the patchworklib. If you want to import plots generated baseon 
    seabron.axisgrid.xxGrid objects as patchworklib.Brick(s) object by using 
    `load_seaborngrid` function, you should execute the function in advance.

    Returns
    -------
    None.
    
    """ 

    #sns.pairplot = mg.pairplot
    sns.axisgrid.Grid._figure          = _basefigure
    sns.axisgrid.Grid.add_legend       = mg.add_legend
    sns.axisgrid.FacetGrid.__init__    = mg.__init_for_facetgrid__
    sns.axisgrid.FacetGrid.despine     = mg.despine 
    sns.axisgrid.PairGrid.__init__     = mg.__init_for_pairgrid__
    sns.axisgrid.JointGrid.__init__    = mg.__init_for_jointgrid__
    sns.matrix.ClusterGrid.__init__    = mg.__init_for_clustergrid__ 
    sns.matrix.ClusterGrid.__setattr__ = mg.__setattr_for_clustergrid__ 
    sns.matrix.ClusterGrid.plot        = mg.__plot_for_clustergrid__

@ponnhide

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions