Skip to content

Commit 4f8dfc0

Browse files
Hideto MoriHideto Mori
Hideto Mori
authored and
Hideto Mori
committed
removed distutils
1 parent 9f9b7e1 commit 4f8dfc0

File tree

2 files changed

+49
-47
lines changed

2 files changed

+49
-47
lines changed

patchworklib/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .patchworklib import *
2-
__version__ = "0.6.4"
2+
__version__ = "0.6.5"

patchworklib/patchworklib.py

+48-46
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import pickle
99
import warnings
1010
from math import log10 , floor
11-
from distutils.version import LooseVersion, StrictVersion
11+
from packaging.version import Version
12+
#from distutils.version import LooseVersion, StrictVersion
1213

1314
import matplotlib
1415
import matplotlib.font_manager as fm
@@ -173,7 +174,7 @@ def _reset_ggplot_legend(bricks):
173174
"""
174175

175176
if "_ggplot_legend" in bricks.__dict__ and bricks._ggplot_legend is not None:
176-
if (matplotlib.__version__) >= StrictVersion("3.7"):
177+
if Version(matplotlib.__version__) >= Version("3.7"):
177178
for tmp_artist in bricks._case.artists:
178179
if tmp_artist == bricks._ggplot_legend:
179180
tmp_artist.remove()
@@ -199,7 +200,10 @@ def _reset_ggplot_legend(bricks):
199200

200201
if "_seaborn_legend" in bricks.__dict__ and bricks._seaborn_legend is not None:
201202
old_legend = bricks._case.legend_
202-
handles = old_legend.legendHandles
203+
if Version(matplotlib.__version__) >= Version("3.8"):
204+
handles = old_legend.legend_handles
205+
else:
206+
handles = old_legend.legendHandles
203207
labels = [t.get_text() for t in old_legend.get_texts()]
204208
title = old_legend.get_title().get_text()
205209
if "bbox_to_anchor" in bricks._seaborn_legend[0]:
@@ -210,7 +214,7 @@ def _reset_ggplot_legend(bricks):
210214
pass
211215

212216
def overwrite_plotnine():
213-
if StrictVersion(plotnine.__version__) >= StrictVersion("0.13"):
217+
if Version(plotnine.__version__) >= Version("0.13"):
214218
plotnine.ggplot.draw = mp9.newdraw
215219
plotnine.facets.facet.setup = mp9.setup
216220
plotnine.facets.facet.make_figure = mp9.make_figure
@@ -243,7 +247,7 @@ def draw_labels(bricks, gori, gcp, figsize):
243247
except KeyError:
244248
pad_x = 4
245249
else:
246-
if StrictVersion(plotnine_version) >= StrictVersion("0.12"):
250+
if Version(plotnine.__version__) >= Version("0.12"):
247251
pad_x = 16 + (get_property('axis_text_x', 'size') - 11) * 0.5 + (get_property('axis_title_x', 'size') - 11) * 0.5
248252
else:
249253
pad_x = margin.get_as('t', 'pt')
@@ -253,7 +257,7 @@ def draw_labels(bricks, gori, gcp, figsize):
253257
except KeyError:
254258
pad_y = 4
255259
else:
256-
if StrictVersion(plotnine_version) >= StrictVersion("0.12"):
260+
if Version(plotnine.__version__) >= Version("0.12"):
257261
pad_y = 13 + (get_property('axis_text_y', 'size') - 11) * 0.5 + (get_property('axis_title_y', 'size') - 11) * 0.5
258262
else:
259263
pad_y = margin.get_as('r', 'pt')
@@ -283,7 +287,7 @@ def draw_labels(bricks, gori, gcp, figsize):
283287
xlabel = bricks.set_xlabel(labels.x, labelpad=pad_x, va="top")
284288
ylabel = bricks.set_ylabel(labels.y, labelpad=pad_y)
285289

286-
if StrictVersion(plotnine_version) >= StrictVersion("0.13"):
290+
if Version(plotnine.__version__) >= Version("0.13"):
287291
gori.theme.targets.axis_title_x = xlabel
288292
gori.theme.targets.axis_title_y = ylabel
289293
if 'axis_title_x' in gori.theme.themeables:
@@ -302,8 +306,7 @@ def draw_labels(bricks, gori, gcp, figsize):
302306
for ax in gori.axs:
303307
gori.theme.themeables[key].apply_ax(ax)
304308

305-
306-
elif StrictVersion(plotnine_version) >= StrictVersion("0.12"):
309+
elif Version(plotnine.__version__) >= Version("0.12"):
307310
gori.theme._targets['axis_title_x'] = xlabel
308311
gori.theme._targets['axis_title_y'] = ylabel
309312
if 'axis_title_x' in gori.theme.themeables:
@@ -340,15 +343,15 @@ def draw_labels(bricks, gori, gcp, figsize):
340343
def draw_legend(bricks, gori, gcp, figsize):
341344
get_property = gcp.theme.themeables.property
342345
#print(get_property)
343-
if StrictVersion(plotnine_version) >= StrictVersion("0.13"):
346+
if Version(plotnine.__version__) >= Version("0.13"):
344347
legend = gcp.guides._build()
345348
if len(legend) == 0:
346349
return None
347350
legend_box = legend[0].draw()
348351
gcp.guides._apply_guide_themes(legend)
349352
wratio = 1
350353
hratio = 1
351-
elif StrictVersion(plotnine_version) >= StrictVersion("0.12"):
354+
elif Version(plotnine.__version__) >= Version("0.12"):
352355
legend_box = gcp.guides.build(gcp)
353356
wratio = 1
354357
hratio = 1
@@ -363,7 +366,7 @@ def draw_legend(bricks, gori, gcp, figsize):
363366
except KeyError:
364367
spacing = 0.1
365368

366-
if StrictVersion(plotnine_version) >= StrictVersion("0.13"):
369+
if Version(plotnine.__version__) >= Version("0.13"):
367370
spacing = gcp.theme.getp('legend_box_spacing')
368371
position = gcp.theme.getp("legend_position")
369372
else:
@@ -413,7 +416,7 @@ def draw_legend(bricks, gori, gcp, figsize):
413416
bricks._ggplot_legend_loc = loc
414417
bricks._ggplot_legend_x = x
415418
bricks._ggplot_legend_y = y
416-
if StrictVersion(plotnine_version) >= StrictVersion("0.13"):
419+
if Version(plotnine.__version__) >= Version("0.13"):
417420
#from plotnine.themes.theme import themeable, theme_update
418421
#gori.theme.themeables['legend_background'] = themeable.from_class_name('legend_background', anchored_box)
419422
for key in gori.theme.themeables:
@@ -422,8 +425,8 @@ def draw_legend(bricks, gori, gcp, figsize):
422425
gori.theme.themeables[key].apply_figure(gori.figure, gori.theme.targets)
423426
for ax in gori.axs:
424427
gori.theme.themeables[key].apply_ax(ax)
425-
426-
elif StrictVersion(plotnine_version) >= StrictVersion("0.12"):
428+
429+
elif Version(plotnine.__version__) >= Version("0.12"):
427430
gori.theme._targets['legend_background'] = anchored_box
428431
for key in gori.theme.themeables:
429432
if "legend" in key:
@@ -491,17 +494,18 @@ def draw_title(bricks, gori, gcp, figsize):
491494
else:
492495
text = bricks._case.set_title(title, pad=pad, fontsize=fontsize, x=x, ha=ha, va=va)
493496

494-
if StrictVersion(plotnine_version) >= StrictVersion("0.13"):
497+
if Version(plotnine.__version__) >= Version("0.13"):
495498
gori.theme.targets.plot_title = text
496499
gori.theme.themeables['plot_title'].apply_figure(gori.figure, gori.theme.targets)
497500
for ax in gori.axs:
498501
gori.theme.themeables['plot_title'].apply_ax(ax)
499-
500-
elif StrictVersion(plotnine_version) >= StrictVersion("0.12"):
502+
503+
elif Version(plotnine.__version__) >= Version("0.12"):
501504
gori.theme._targets['plot_title'] = text
502505
gori.theme.themeables['plot_title'].apply_figure(gori.figure, gori.theme._targets)
503506
for ax in gori.axs:
504507
gori.theme.themeables['plot_title'].apply_ax(ax)
508+
505509
else:
506510
gori.figure._themeable['plot_title'] = text
507511
gori.theme.themeables['plot_title'].apply_figure(gori.figure)
@@ -520,7 +524,7 @@ def draw_title(bricks, gori, gcp, figsize):
520524
position_dict[key] = axtmp.get_position()
521525

522526
gcp = copy.deepcopy(ggplot)
523-
if StrictVersion(plotnine_version) >= StrictVersion("0.12"):
527+
if Version(plotnine.__version__) >= Version("0.12"):
524528
figure_subplot_wspace_ori = matplotlib.rcParams["figure.subplot.wspace"]
525529
figure_subplot_hspace_ori = matplotlib.rcParams["figure.subplot.hspace"]
526530
figsize_ori = gcp.theme.themeables['figure_size'].properties["value"]
@@ -544,8 +548,8 @@ def draw_title(bricks, gori, gcp, figsize):
544548
strips = []
545549

546550
ggplot._build()
547-
548-
if StrictVersion(plotnine_version) >= StrictVersion("0.13"):
551+
552+
if Version(plotnine.__version__) >= Version("0.13"):
549553
ggplot.facet.make_figure = mp9.make_figure
550554
fig, axs = plotnine.facets.facet.setup(ggplot.facet, _basefigure, ggplot)
551555
else:
@@ -557,10 +561,10 @@ def draw_title(bricks, gori, gcp, figsize):
557561
ggplot.figure = _basefigure
558562
ggplot.axs = axs
559563

560-
if StrictVersion(plotnine_version) >= StrictVersion("0.13"):
564+
if Version(plotnine.__version__) >= Version("0.13"):
561565
ggplot.theme = gcp.theme
562-
563-
elif StrictVersion(plotnine_version) >= StrictVersion("0.12"):
566+
567+
elif Version(plotnine.__version__) >= Version("0.12"):
564568
ggplot.theme = gcp.theme
565569
ggplot.theme._targets = gcp.theme._targets
566570

@@ -582,21 +586,20 @@ def draw_title(bricks, gori, gcp, figsize):
582586
ggplot.axs[i].spines[bar].set_ec(gcp.axs[i].spines[bar].get_ec())
583587
ggplot.axs[i].spines[bar].set_visible(gcp.axs[i].spines[bar].get_visible())
584588

585-
if StrictVersion(plotnine_version) >= StrictVersion("0.13"):
589+
if Version(plotnine.__version__) >= Version("0.13"):
586590
ggplot.theme.setup(ggplot)
587591
else:
588592
ggplot._setup_parameters()
589593
ggplot.facet.strips.generate()
590594

591595
for i in range(len(ggplot.facet.strips)):
592-
if StrictVersion(plotnine_version) >= StrictVersion("0.13"):
596+
if Version(plotnine.__version__) >= Version("0.13"):
593597
ggplot.facet.strips[i].label_info = strips[i].label_info
594598
ggplot.facet.strips[i].layout_info = strips[i].layout_info
595599
ggplot.facet.strips[i].theme = strips[i].theme
596600
ggplot.facet.strips[i].position = strips[i].position
597601
ggplot.facet.strips[i].figure = ggplot.facet.strips[i].ax
598-
599-
elif StrictVersion(plotnine_version) >= StrictVersion("0.12"):
602+
elif Version(plotnine.__version__) >= Version("0.12"):
600603
ggplot.facet.strips[i].position = strips[i].draw_info.position
601604
ggplot.facet.strips[i].draw_info.box_height = strips[i].draw_info.box_height
602605
ggplot.facet.strips[i].draw_info.box_width = strips[i].draw_info.box_width
@@ -620,14 +623,14 @@ def draw_title(bricks, gori, gcp, figsize):
620623
ggplot.facet.strips[i].info.y = strips[i].info.y
621624

622625
#Drawing
623-
if StrictVersion(plotnine_version) >= StrictVersion("0.12"):
626+
if Version(plotnine.__version__) >= Version("0.13"):
624627
from plotnine._mpl.layout_engine import PlotnineLayoutEngine
625628
from plotnine.themes.themeable import Themeables, themeable
626629
for i, l in enumerate(ggplot.layers, start=1):
627630
l.zorder = i + 10
628631
l.draw(ggplot.layout, ggplot.coordinates)
629632

630-
if StrictVersion(plotnine_version) >= StrictVersion("0.13"):
633+
if Version(plotnine.__version__) >= Version("0.13"):
631634
ggplot._draw_panel_borders()
632635
ggplot.facet.theme = ggplot.theme
633636

@@ -637,7 +640,7 @@ def draw_title(bricks, gori, gcp, figsize):
637640
ggplot.theme.themeables["figure_size"] = new("figure_size",(1,1))
638641
ggplot.theme.apply()
639642

640-
elif StrictVersion(plotnine_version) >= StrictVersion("0.9"):
643+
elif Version(plotnine.__version__) >= Version("0.9"):
641644
ggplot._resize_panels()
642645
for i, l in enumerate(ggplot.layers, start=1):
643646
l.zorder = i + 10
@@ -646,7 +649,7 @@ def draw_title(bricks, gori, gcp, figsize):
646649
ggplot._draw_watermarks()
647650
ggplot.theme.apply(ggplot.figure, axs)
648651

649-
elif StrictVersion("0.8") <= StrictVersion(plotnine_version) < StrictVersion("0.9"):
652+
elif Version("0.8") <= Version(plotnine.__version__) < Version("0.9"):
650653
ggplot._resize_panels()
651654
ggplot._draw_layers()
652655
ggplot._draw_breaks_and_labels()
@@ -661,14 +664,13 @@ def draw_title(bricks, gori, gcp, figsize):
661664
if "_ggplot_legend" in ax.__dict__:
662665
ax._ggplot_legend = None #For Google colab...
663666
ax.change_plotsize((figsize[0], figsize[1]))
664-
665-
if StrictVersion(plotnine_version) >= StrictVersion("0.9"):
667+
if Version(plotnine.__version__) >= Version("0.9"):
666668
xl, yl = draw_labels(ax, ggplot, gcp, figsize)
667669

668670
draw_legend(ax, ggplot, gcp, figsize) #0.13 makes Erros here.
669671
draw_title(ax, ggplot, gcp, figsize)
670-
671-
elif StrictVersion("0.8") <= StrictVersion(plotnine_version) < StrictVersion("0.9"):
672+
673+
elif Version("0.8") <= Version(plotnine.__version__) < Version("0.9"):
672674
draw_labels(ax, ggplot, gcp, figsize)
673675
draw_legend(ax, ggplot, gcp, figsize)
674676
draw_title(ax, ggplot, gcp, figsize)
@@ -682,7 +684,7 @@ def draw_title(bricks, gori, gcp, figsize):
682684
axtmp = _axes_dict[key]
683685
axtmp.set_position(position_dict[key])
684686

685-
if StrictVersion(plotnine_version) >= StrictVersion("0.12"):
687+
if Version(plotnine.__version__) >= Version("0.12"):
686688
ax.set_xlabel(xl)
687689
ax.set_ylabel(yl)
688690
return_obj = ax
@@ -701,13 +703,13 @@ def draw_title(bricks, gori, gcp, figsize):
701703
bricks = Bricks(bricks_dict=bricks_dict)
702704
bricks = expand(bricks, width, height)
703705

704-
if StrictVersion(plotnine_version) >= StrictVersion("0.9"):
706+
if Version(plotnine.__version__) >= Version("0.9"):
705707
xl, yl = draw_labels(bricks, ggplot, gcp, figsize)
706708
draw_legend(bricks, ggplot, gcp, figsize)
707709
draw_title(bricks, ggplot, gcp, figsize)
708710
pass
709-
710-
elif StrictVersion("0.8") <= StrictVersion(plotnine_version) < StrictVersion("0.9"):
711+
712+
elif Version("0.8") <= Version(plotnine.__version__) < Version("0.9"):
711713
draw_labels(bricks, ggplot, gcp, figsize)
712714
draw_legend(bricks, ggplot, gcp, figsize)
713715
draw_title(bricks, ggplot, gcp, figsize)
@@ -724,12 +726,12 @@ def draw_title(bricks, gori, gcp, figsize):
724726
x0, x1, y0, y1 = bricks.get_outer_corner()
725727
bricks._originalsize = (abs(x1-x0), abs(y0-y1))
726728
bricks.set_originalpositions()
727-
if StrictVersion(plotnine_version) >= StrictVersion("0.12"):
729+
if Version(plotnine.__version__) >= Version("0.12"):
728730
bricks.case.set_xlabel(xl)
729731
bricks.case.set_ylabel(yl)
730732
return_obj = bricks
731733

732-
if StrictVersion(plotnine_version) >= StrictVersion("0.12"):
734+
if Version(plotnine.__version__) >= Version("0.12"):
733735
matplotlib.rcParams["figure.subplot.wspace"] = figure_subplot_wspace_ori
734736
matplotlib.rcParams["figure.subplot.hspace"] = figure_subplot_hspace_ori
735737
return_obj.savefig(_ggplot=True)
@@ -2405,7 +2407,7 @@ def move_legend(self, new_loc, **kws):
24052407
"""
24062408
old_legend = self._case.legend_
24072409

2408-
if (matplotlib.__version__) >= StrictVersion("3.8"):
2410+
if Version(matplotlib.__version__) >= Version("3.8"):
24092411
handles = old_legend.legend_handles
24102412
else:
24112413
handles = old_legend.legendHandles
@@ -3080,7 +3082,7 @@ def move_legend(self, new_loc, **kws):
30803082
self._comeback()
30813083
old_legend = self.legend_
30823084

3083-
if (matplotlib.__version__) >= StrictVersion("3.8"):
3085+
if Version(matplotlib.__version__) >= Version("3.8"):
30843086
handles = old_legend.legend_handles
30853087
else:
30863088
handles = old_legend.legendHandles
@@ -3598,7 +3600,7 @@ def resize(self, direction):
35983600
#bricks2 = (brick2 | (brick5 / brick4)) / (brick1 | brick3)
35993601
ax21543 = (ax2 / ax1) | (ax5 / ax4 / ax3)
36003602
ax21543.savefig("test2.pdf")
3601-
3602-
if StrictVersion(plotnine.__version__) >= StrictVersion("0.12"):
3603+
3604+
if Version(plotnine.__version__) >= Version("0.12"):
36033605
overwrite_plotnine()
36043606

0 commit comments

Comments
 (0)