31
31
#warnings.simplefilter('ignore', SettingWithCopyWarning)
32
32
warnings .simplefilter ('ignore' )
33
33
34
- __version__ = "0.6.4 "
34
+ __version__ = "0.6.5 "
35
35
_basefigure = plt .figure (figsize = (1 ,1 ))
36
36
_render = _basefigure .canvas .get_renderer ()
37
37
_scale = Affine2D ().scale (1. / _basefigure .dpi )
@@ -244,7 +244,7 @@ def draw_labels(bricks, gori, gcp, figsize):
244
244
pad_x = 4
245
245
else :
246
246
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
248
248
else :
249
249
pad_x = margin .get_as ('t' , 'pt' )
250
250
@@ -254,7 +254,7 @@ def draw_labels(bricks, gori, gcp, figsize):
254
254
pad_y = 4
255
255
else :
256
256
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
258
258
else :
259
259
pad_y = margin .get_as ('r' , 'pt' )
260
260
@@ -339,21 +339,36 @@ def draw_labels(bricks, gori, gcp, figsize):
339
339
340
340
def draw_legend (bricks , gori , gcp , figsize ):
341
341
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 )
344
353
wratio = 1
345
354
hratio = 1
346
355
else :
356
+ legend_box = gcp .guides .build (gcp )
347
357
wratio = figsize [0 ]
348
358
hratio = figsize [1 ]
349
359
360
+ #print(legend_box, dir(legend_box[0]))
350
361
try :
351
362
spacing = get_property ('legend_box_spacing' )
352
363
except KeyError :
353
364
spacing = 0.1
354
365
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
355
371
356
- position = gcp .guides .position
357
372
if position == 'right' :
358
373
loc = 6
359
374
x = 1.0 + spacing / wratio
@@ -398,7 +413,17 @@ def draw_legend(bricks, gori, gcp, figsize):
398
413
bricks ._ggplot_legend_loc = loc
399
414
bricks ._ggplot_legend_x = x
400
415
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" ):
402
427
gori .theme ._targets ['legend_background' ] = anchored_box
403
428
for key in gori .theme .themeables :
404
429
if "legend" in key :
@@ -564,7 +589,14 @@ def draw_title(bricks, gori, gcp, figsize):
564
589
ggplot .facet .strips .generate ()
565
590
566
591
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" ):
568
600
ggplot .facet .strips [i ].position = strips [i ].draw_info .position
569
601
ggplot .facet .strips [i ].draw_info .box_height = strips [i ].draw_info .box_height
570
602
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):
598
630
if StrictVersion (plotnine_version ) >= StrictVersion ("0.13" ):
599
631
ggplot ._draw_panel_borders ()
600
632
ggplot .facet .theme = ggplot .theme
633
+
601
634
ggplot ._draw_breaks_and_labels ()
602
635
ggplot ._draw_watermarks ()
603
636
new = themeable .from_class_name
@@ -631,6 +664,7 @@ def draw_title(bricks, gori, gcp, figsize):
631
664
632
665
if StrictVersion (plotnine_version ) >= StrictVersion ("0.9" ):
633
666
xl , yl = draw_labels (ax , ggplot , gcp , figsize )
667
+
634
668
draw_legend (ax , ggplot , gcp , figsize ) #0.13 makes Erros here.
635
669
draw_title (ax , ggplot , gcp , figsize )
636
670
0 commit comments