Search code examples
pythonpandaspandas-profiling

Customise plots in pandas-profiling (change colors/colorbar in correlation heatmap/..)


I have searched pandas profiling documentation and their advanced usage webpage but I could not find how to customise plots that it generates. Eg. now it shows correlation matrices with colorbar having blue as 1 and red as -1. What if I want to reverse the colours? Or change the palette fully? The advanced options allow to skip some parts or change defaults for computing correlations but is it possible to pass arguments to the underlying matplotlib? My guess is that this is responsible for the correlation plot but a) I do not know how to pass anything to it; b) what about other plots (eg. interactions)?

example


Solution

  • The way how to do that is using the plot argument and then change the cmap. It was not documented at that time. One can use any palette from seaborn or their own and it's possible to also adjust the other plot settings. The syntax is then:

    import seaborn as sns
    from pandas_profiling import ProfileReport
    
    planets = sns.load_dataset("planets")
    
    # drop the one participant who did not submit
    profile = ProfileReport(planets, title='Pandas Profiling Report', explorative=True,
                           plot={
                               'correlation':{
                                   'cmap': 'RdBu_r',
                                   'bad': '#000000'}}
                           )
    # profile.to_widgets()
    profile.to_notebook_iframe()
    

    yielding:

    correlation map

    All the possible tweaks and adjustments and default settings are in this.