Skip to content

Doesn't work with Plotnine Seaborn Theme #37

Description

@ZwFink

Hello,
The following code fails when theme_seaborn is used in plotnine:

from plotnine import *
import pandas as pd
import patchworklib as pw
df = pd.DataFrame(columns=['benchmark', 'technique', 'value', 'platform'])
df.loc[0] = ['BO', 'Item1', 3.0, 'A']
df.loc[1] = ['BO', 'Item2', 2.0, 'A']
df.loc[2] = ['BO', 'Item3', 4.0, 'A']
df.loc[3] = ['BO', 'Item1', 5.0, 'B']
df.loc[4] = ['BO', 'Item2', 2.0, 'B']
df.loc[5] = ['BO', 'Item3', 6.0, 'B']
p1=(
    ggplot(df, aes(fill="technique", y="value", x="value")) + theme_seaborn() + 
    geom_col(stat='identity', position='dodge')
)
p1_b = pw.load_ggplot(ggplot=p1, figsize=(5,4))

with the following error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[56], line 16
     11 df.loc[5] = ['BO', 'Item3', 6.0, 'B']
     12 p1=(
     13     ggplot(df, aes(fill="technique", y="value", x="value")) + theme_seaborn() + 
     14     geom_col(stat='identity', position='dodge')
     15 )
---> 16 p1_b = pw.load_ggplot(ggplot=p1, figsize=(5,4))

File [~/.local/lib/python3.9/site-packages/patchworklib/patchworklib.py:437](https://file+.vscode-resource.vscode-cdn.net/home/zane/projects/LLNL/hpac_performance/2023-02-01_amdgpu/analysis/~/.local/lib/python3.9/site-packages/patchworklib/patchworklib.py:437), in load_ggplot(ggplot, figsize)
    434 ax.change_aspectratio((figsize[0], figsize[1])) 
    436 if StrictVersion(plotnine_version) >= StrictVersion("0.9"):
--> 437     draw_labels(ax, ggplot, gcp) 
    438     draw_legend(ax, ggplot, gcp, figsize)
    439     draw_title(ax,  ggplot, gcp, figsize)

File [~/.local/lib/python3.9/site-packages/patchworklib/patchworklib.py:273](https://file+.vscode-resource.vscode-cdn.net/home/zane/projects/LLNL/hpac_performance/2023-02-01_amdgpu/analysis/~/.local/lib/python3.9/site-packages/patchworklib/patchworklib.py:273), in load_ggplot..draw_labels(bricks, gori, gcp)
    270 gori.figure._themeable['axis_title_x'] = xlabel
    271 gori.figure._themeable['axis_title_y'] = ylabel
--> 273 gori.theme.themeables['axis_title_x'].apply_figure(gori.figure)
    274 for ax in gori.axs:
    275     gori.theme.themeables['axis_title_x'].apply(ax)

KeyError: 'axis_title_x'

But it does work when theme_seaborn() is commented out. It looks like the plotnine seaborn theme doesn't define theme.themeables['axis_title_x'].

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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