patchworklib icon indicating copy to clipboard operation
patchworklib copied to clipboard

Some themes of plotnine don't work

Open CavalloneChen opened this issue 3 years ago • 4 comments

For example, theme_seaborn and theme_matplotlib don't work image

CavalloneChen avatar Apr 20 '22 06:04 CavalloneChen

Thank you for reporting this problem. I did not realize it. I will check and fix the problem as soon as possible. Could you give me a text-based, not image-based example code that can reproduce the above error?

ponnhide avatar Apr 20 '22 07:04 ponnhide

Thank you for reporting this problem. I did not realize it. I will check and fix the problem as soon as possible. Could you give me a text-based, not image-based example code that can reproduce the above error?

import os
import time
import pandas as pd
import patchworklib as pw
import numpy as np
from plotnine import *
from plotnine.data import *
t0 = time.time()
quick = True

if "flights.csv" in os.listdir():
    pass
else:
    os.system("wget https://raw.githubusercontent.com/mwaskom/seaborn-data/master/flights.csv")
flights = pd.read_csv('flights.csv')
months = flights['month'].unique()  # Months ordered January, ..., December
flights['month'] = pd.Categorical(flights['month'], categories=months)
flights.head()
text_color = np.array(['black']*len(flights))
text_color[flights['passengers']<300] = 'white'
g = (ggplot(flights, aes('factor(year)', 'month', fill='passengers'))
 + geom_tile(aes(width=.95, height=.95))
 + geom_text(aes(label='passengers'), size=10, color=text_color)
 + scale_y_discrete(limits=months[::-1])    
 + theme_seaborn()      
 + theme(                                         
     axis_ticks=element_blank(),
     panel_background=element_rect(fill='white'))
)
g1 = pw.load_ggplot(g, figsize=(4,4))
g1.savefig(quick=quick)

CavalloneChen avatar Apr 20 '22 07:04 CavalloneChen

I have updated the GitHub repository. If you want to use patchworklib that fixed the above problem, please install it from GitHub by pip install git+https://github.com/ponnhide/patchworklib.git command.

However, I'm not sure if this modification correctly reflects the theme specified by plotnine because I simply modified the code to just avoid the above error. Anyway, the above error can be avoided in the current implementation. I will consider a more appropriate modification.

ponnhide avatar Apr 20 '22 13:04 ponnhide

I have updated the GitHub repository. If you want to use patchworklib that fixed the above problem, please install it from GitHub by pip install git+https://github.com/ponnhide/patchworklib.git command.

However, I'm not sure if this modification correctly reflects the theme specified by plotnine because I simply modified the code to just avoid the above error. Anyway, the above error can be avoided in the current implementation. I will consider a more appropriate modification.

Thanks for the quick fix. Just tested it, errors were gone, but the themes were not reflected. Looking forward to future patch :-)

CavalloneChen avatar Apr 20 '22 13:04 CavalloneChen