BioSTEAMDevelopmentGroup / biosteam

The Biorefinery Simulation and Techno-Economic Analysis Modules; Life Cycle Assessment; Chemical Process Simulation Under Uncertainty
Other
176 stars 35 forks source link

Adds a parameter to plot_spearman_1d and format_spearman_plot to allow changing the x-axis title #154

Closed sarangbhagwat closed 1 year ago

sarangbhagwat commented 1 year ago

Minor addition -- allows setting the x-axis title text in Spearman's rank order correlation correlation plots. Default title is the same as before.

yoelcortes commented 1 year ago

@sarangbhagwat, thanks for the pull request.

When using default kwargs, passing None will override the default. Your changes lead to a bug in the x-axis label because of this. Here is simplified code that shows that the default label for plot_spearman_1d actually turns to None.

def format_spearman_plot(xlabel='some default'):
    assert xlabel is None # Note that this is True when plot_spearman_1d() is run

def plot_spearman_1d(xlabel=None):
    format_spearman_plot(xlabel)

plot_spearman_1d()

In general, try using None for default kwargs. It becomes easier to write functions within functions without having to remember what were the default kwargs. For example:

def format_spearman_plot(xlabel=None):
    if xlabel is None: xlabel = 'some default'

def plot_spearman_1d(xlabel=None):
    format_spearman_plot(xlabel)

I took care of this and changed xlabel_fn to xlabel (which expects a string if passed).

Thanks,