Skip to content

Commit

Permalink
plots: add plot_kwargs as argument
Browse files Browse the repository at this point in the history
plot_kwargs is passed to seaborns plot function so arbitrary args can be
defined in the recipe that are specific to certain plot types, e.g.
creating a complementary eCDF
  • Loading branch information
awillecke committed May 31, 2024
1 parent 406d620 commit 0987e62
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ class PlottingTask(YAMLObject):
y: str
the name of the column with the data to plot on the y-axis
plot_kwargs:
keyword args that are passed to the plot function. Availabler args depend on the plot_type
selector: Optional[Union[Callable, str]]
a query string for selecting a subset of the input DataFrame for
plotting, see
Expand Down Expand Up @@ -213,6 +216,7 @@ def __init__(self, dataset_name:str
, plot_types:Optional[List[str]] = None
, ys:Optional[List[str]] = None
, selector:Optional[Union[Callable, str]] = None
, plot_kwargs:Optional[dict] = None
, column:str = None
, row:str = None
, hue:str = None
Expand Down Expand Up @@ -280,6 +284,15 @@ def __init__(self, dataset_name:str
self.ys = None


if plot_kwargs:
# parse plot kwargs
if type(plot_kwargs) == dict:
self.plot_kwargs = plot_kwargs
else:
loge(f"plot_kwargs set but is not a dict: {plot_kwargs=}")
else:
self.plot_kwargs = dict()

self.selector = selector

self.column = column if column != '' else None
Expand Down Expand Up @@ -546,6 +559,7 @@ def distributionplot(plot_type):
, x=self.x, y=self.y
, hue=self.hue
, row=self.row, column=self.column
, kwargs=self.plot_kwargs
)

def catplot(plot_type):
Expand All @@ -554,6 +568,7 @@ def catplot(plot_type):
, x=self.x, y=self.y
, hue=self.hue
, row=self.row, column=self.column
, kwargs=self.plot_kwargs
)

def relplot(plot_type):
Expand All @@ -562,6 +577,7 @@ def relplot(plot_type):
, x=self.x, y=self.y
, hue=self.hue, style=self.style, size=self.size
, row=self.row, column=self.column
, kwargs=self.plot_kwargs
)

def heatplot(plot_type):
Expand All @@ -570,6 +586,7 @@ def heatplot(plot_type):
, x=self.x, y=self.y
, hue=self.hue, style=self.style
, row=self.row, column=self.column
, kwargs=self.plot_kwargs
)

fig = None
Expand Down Expand Up @@ -812,26 +829,27 @@ def set_plot_specific_options(self, plot_type:str, kwargs:dict):
return kwargs

def plot_distribution(self, df, x='value', y=None, hue='moduleName', row='dcc', column='traciStart', plot_type='ecdf', **kwargs):
kwargs = self.set_plot_specific_options(plot_type, kwargs)
kwargs = self.set_plot_specific_options(plot_type, **kwargs)

logd(f'PlottingTask::plot_distribution: {df.columns=}')
logd(f'PlottingTask::plot_distribution: {x=}')
logd(f'PlottingTask::plot_distribution: {y=}')
logd(f'PlottingTask::plot_distribution: {plot_type=}')
logd(f'PlottingTask::plot_distribution: {kwargs=}')
grid = sb.displot(data=df, x=x
, row=row, col=column
, hue=hue
, kind=plot_type
# , legend_out=False
# , **kwargs
, **kwargs
)

grid = self.set_grid_defaults(grid)

return grid

def plot_catplot(self, df, x='v2x_rate', y='cbr', hue='moduleName', row='dcc', column='traciStart', plot_type='box', **kwargs):
kwargs = self.set_plot_specific_options(plot_type, kwargs)
kwargs = self.set_plot_specific_options(plot_type, **kwargs)

logd(f'PlottingTask::plot_catplot: {df.columns=}')
grid = sb.catplot(data=df, x=x, y=y, row=row, col=column
Expand All @@ -847,7 +865,7 @@ def plot_catplot(self, df, x='v2x_rate', y='cbr', hue='moduleName', row='dcc', c


def plot_relplot(self, df, x='v2x_rate', y='cbr', hue='moduleName', style='prefix', size=None, row='dcc', column='traciStart', plot_type='line', **kwargs):
kwargs = self.set_plot_specific_options(plot_type, kwargs)
kwargs = self.set_plot_specific_options(plot_type, **kwargs)

logd(f'PlottingTask::plot_relplot: {df.columns=}')
grid = sb.relplot(data=df, x=x, y=y, row=row, col=column
Expand Down

0 comments on commit 0987e62

Please sign in to comment.