Skip to content

Commit

Permalink
Refactor generate_plot function to handle facet_row and facet_col gro…
Browse files Browse the repository at this point in the history
…ups properly
  • Loading branch information
adkinsrs committed Aug 12, 2024
1 parent 9c6ad43 commit 11e4f2a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/gear/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,16 @@ def generate_plot(df, x=None, y=None, z=None, facet_row=None, facet_col=None,
# Map indexes for subplot ordering. Indexes start at 1 since plotting rows/cols start at 1
facet_row_groups = []
facet_col_groups = []
row_titles = None
column_titles = None

if facet_row:
facet_row_groups = category_orders[facet_row] if facet_row in category_orders else df[facet_row].unique()
row_titles = facet_row_groups

if facet_col:
facet_col_groups = category_orders[facet_col] if facet_col in category_orders else df[facet_col].unique()
column_titles = facet_col_groups

facet_row_indexes = {group: idx for idx, group in enumerate(facet_row_groups, start=1)}
num_rows = len(facet_row_groups) if facet_row else 1
Expand All @@ -485,8 +489,8 @@ def generate_plot(df, x=None, y=None, z=None, facet_row=None, facet_col=None,
# Make faceted plot
fig = make_subplots(rows=num_rows
, cols=num_cols
, row_titles=facet_row_groups if facet_row else None
, column_titles=facet_col_groups if facet_col else None
, row_titles=row_titles
, column_titles=column_titles
, x_title=x_title if x_title else None
, y_title=y_title if y_title else None
)
Expand Down

0 comments on commit 11e4f2a

Please sign in to comment.