Skip to content

Commit 9363fac

Browse files
Hideto MoriHideto Mori
Hideto Mori
authored and
Hideto Mori
committed
Support plotnine v0.13.6
1 parent 235bfbc commit 9363fac

File tree

4 files changed

+55
-13
lines changed

4 files changed

+55
-13
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ If you want to use developmental version, it can be installed using the followin
1717
`pip install git+https://github.com/ponnhide/patchworklib.git`
1818

1919
## News
20+
#### 10122024: version 0.6.5 is released.
21+
- Seaborn v0.13.X is now supported.
22+
- plotnine v0.13.6 might be supported.
23+
2024
#### 10232023: version 0.6.3 is released.
2125
- Seaborn v0.13.0 is now supported.
22-
- I have confirmed patchworklib still works forplotnine v0.12.3.
26+
- I have confirmed patchworklib still works for plotnine v0.12.3.
2327

2428
#### 05162023: version 0.6.1 was released.
2529
- I could not fully support plotnine version 0.12.1 (It works, but patchworklib arrangement results are not as expected). Maybe, I will do not support plotnine in the future.

patchworklib/modified_plotnine.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ def newdraw(self, return_ggplot=False, show: bool = False):
9191

9292
# setup
9393
self.figure, self.axs = self.facet.setup(self)
94-
self.guides._setup(self)
94+
try:
95+
self.guides._setup(self)
96+
except:
97+
pass
98+
9599
self.theme.setup(self)
96100

97101
# Drawing

patchworklib/patchworklib.py

+42-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#warnings.simplefilter('ignore', SettingWithCopyWarning)
3232
warnings.simplefilter('ignore')
3333

34-
__version__ = "0.6.4"
34+
__version__ = "0.6.5"
3535
_basefigure = plt.figure(figsize=(1,1))
3636
_render = _basefigure.canvas.get_renderer()
3737
_scale = Affine2D().scale(1./_basefigure.dpi)
@@ -244,7 +244,7 @@ def draw_labels(bricks, gori, gcp, figsize):
244244
pad_x = 4
245245
else:
246246
if StrictVersion(plotnine_version) >= StrictVersion("0.12"):
247-
pad_x = 14 + (get_property('axis_text_x', 'size') - 11) * 0.5 + (get_property('axis_title_x', 'size') - 11) * 0.5
247+
pad_x = 16 + (get_property('axis_text_x', 'size') - 11) * 0.5 + (get_property('axis_title_x', 'size') - 11) * 0.5
248248
else:
249249
pad_x = margin.get_as('t', 'pt')
250250

@@ -254,7 +254,7 @@ def draw_labels(bricks, gori, gcp, figsize):
254254
pad_y = 4
255255
else:
256256
if StrictVersion(plotnine_version) >= StrictVersion("0.12"):
257-
pad_y = 12 + (get_property('axis_text_y', 'size') - 11) * 0.5 + (get_property('axis_title_y', 'size') - 11) * 0.5
257+
pad_y = 13 + (get_property('axis_text_y', 'size') - 11) * 0.5 + (get_property('axis_title_y', 'size') - 11) * 0.5
258258
else:
259259
pad_y = margin.get_as('r', 'pt')
260260

@@ -339,21 +339,36 @@ def draw_labels(bricks, gori, gcp, figsize):
339339

340340
def draw_legend(bricks, gori, gcp, figsize):
341341
get_property = gcp.theme.themeables.property
342-
legend_box = gcp.guides.build(gcp)
343-
if StrictVersion(plotnine_version) >= StrictVersion("0.12"):
342+
#print(get_property)
343+
if StrictVersion(plotnine_version) >= StrictVersion("0.13"):
344+
legend = gcp.guides._build()
345+
if len(legend) == 0:
346+
return None
347+
legend_box = legend[0].draw()
348+
gcp.guides._apply_guide_themes(legend)
349+
wratio = 1
350+
hratio = 1
351+
elif StrictVersion(plotnine_version) >= StrictVersion("0.12"):
352+
legend_box = gcp.guides.build(gcp)
344353
wratio = 1
345354
hratio = 1
346355
else:
356+
legend_box = gcp.guides.build(gcp)
347357
wratio = figsize[0]
348358
hratio = figsize[1]
349359

360+
#print(legend_box, dir(legend_box[0]))
350361
try:
351362
spacing = get_property('legend_box_spacing')
352363
except KeyError:
353364
spacing = 0.1
354365

366+
if StrictVersion(plotnine_version) >= StrictVersion("0.13"):
367+
spacing = gcp.theme.getp('legend_box_spacing')
368+
position = gcp.theme.getp("legend_position")
369+
else:
370+
position = gcp.guides.position
355371

356-
position = gcp.guides.position
357372
if position == 'right':
358373
loc = 6
359374
x = 1.0 + spacing/wratio
@@ -398,7 +413,17 @@ def draw_legend(bricks, gori, gcp, figsize):
398413
bricks._ggplot_legend_loc = loc
399414
bricks._ggplot_legend_x = x
400415
bricks._ggplot_legend_y = y
401-
if StrictVersion(plotnine_version) >= StrictVersion("0.12"):
416+
if StrictVersion(plotnine_version) >= StrictVersion("0.13"):
417+
#from plotnine.themes.theme import themeable, theme_update
418+
#gori.theme.themeables['legend_background'] = themeable.from_class_name('legend_background', anchored_box)
419+
for key in gori.theme.themeables:
420+
if "legend" in key:
421+
#print(gori.theme.themeables[key])
422+
gori.theme.themeables[key].apply_figure(gori.figure, gori.theme.targets)
423+
for ax in gori.axs:
424+
gori.theme.themeables[key].apply_ax(ax)
425+
426+
elif StrictVersion(plotnine_version) >= StrictVersion("0.12"):
402427
gori.theme._targets['legend_background'] = anchored_box
403428
for key in gori.theme.themeables:
404429
if "legend" in key:
@@ -564,7 +589,14 @@ def draw_title(bricks, gori, gcp, figsize):
564589
ggplot.facet.strips.generate()
565590

566591
for i in range(len(ggplot.facet.strips)):
567-
if StrictVersion(plotnine_version) >= StrictVersion("0.12"):
592+
if StrictVersion(plotnine_version) >= StrictVersion("0.13"):
593+
ggplot.facet.strips[i].label_info = strips[i].label_info
594+
ggplot.facet.strips[i].layout_info = strips[i].layout_info
595+
ggplot.facet.strips[i].theme = strips[i].theme
596+
ggplot.facet.strips[i].position = strips[i].position
597+
ggplot.facet.strips[i].figure = ggplot.facet.strips[i].ax
598+
599+
elif StrictVersion(plotnine_version) >= StrictVersion("0.12"):
568600
ggplot.facet.strips[i].position = strips[i].draw_info.position
569601
ggplot.facet.strips[i].draw_info.box_height = strips[i].draw_info.box_height
570602
ggplot.facet.strips[i].draw_info.box_width = strips[i].draw_info.box_width
@@ -598,6 +630,7 @@ def draw_title(bricks, gori, gcp, figsize):
598630
if StrictVersion(plotnine_version) >= StrictVersion("0.13"):
599631
ggplot._draw_panel_borders()
600632
ggplot.facet.theme = ggplot.theme
633+
601634
ggplot._draw_breaks_and_labels()
602635
ggplot._draw_watermarks()
603636
new = themeable.from_class_name
@@ -631,6 +664,7 @@ def draw_title(bricks, gori, gcp, figsize):
631664

632665
if StrictVersion(plotnine_version) >= StrictVersion("0.9"):
633666
xl, yl = draw_labels(ax, ggplot, gcp, figsize)
667+
634668
draw_legend(ax, ggplot, gcp, figsize) #0.13 makes Erros here.
635669
draw_title(ax, ggplot, gcp, figsize)
636670

setup.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
URL = 'https://github.com/ponnhide/patchworklib'
1111
LICENSE = 'GNU General Public License v3.0'
1212
DOWNLOAD_URL = 'https://github.com/ponnhide/patchworklib'
13-
VERSION = '0.6.4'
13+
VERSION = '0.6.5'
1414
PYTHON_REQUIRES = ">=3.7"
1515

1616
INSTALL_REQUIRES = [
1717
'matplotlib>=3.4',
1818
'pandas>=0.24',
19-
'numpy>=1.16',
19+
'numpy>=1.16,<1.27',
2020
'dill',
2121
'seaborn',
22-
'plotnine<=0.12.4',
22+
'plotnine<=0.13.6',
2323
]
2424

2525
PACKAGES = [

0 commit comments

Comments
 (0)