ponnhide / patchworklib

Patchwork for matplotlib: A subplot manager for intuitive layouts in matplotlib, seaborn, and plotnine.
GNU General Public License v3.0
382 stars 25 forks source link

Some themes of plotnine don't work #12

Closed CavalloneChen closed 1 year ago

CavalloneChen commented 2 years ago

For example, theme_seaborn and theme_matplotlib don't work

image
ponnhide commented 2 years ago

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?

CavalloneChen commented 2 years ago

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)
ponnhide commented 2 years ago

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.

CavalloneChen commented 2 years ago

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 :-)