@@ -210,7 +210,12 @@ def _reset_ggplot_legend(bricks):
210
210
pass
211
211
212
212
def overwrite_plotnine ():
213
- plotnine .ggplot .draw = mp9 .draw
213
+ if StrictVersion (plotnine .__version__ ) >= StrictVersion ("0.13" ):
214
+ plotnine .ggplot .draw = mp9 .newdraw
215
+ plotnine .facets .facet .setup = mp9 .setup
216
+ plotnine .facets .facet .make_figure = mp9 .make_figure
217
+ else :
218
+ plotnine .ggplot .draw = mp9 .draw
214
219
215
220
def load_ggplot (ggplot = None , figsize = None ):
216
221
"""
@@ -277,8 +282,28 @@ def draw_labels(bricks, gori, gcp, figsize):
277
282
else :
278
283
xlabel = bricks .set_xlabel (labels .x , labelpad = pad_x , va = "top" )
279
284
ylabel = bricks .set_ylabel (labels .y , labelpad = pad_y )
285
+
286
+ if StrictVersion (plotnine_version ) >= StrictVersion ("0.13" ):
287
+ gori .theme .targets .axis_title_x = xlabel
288
+ gori .theme .targets .axis_title_y = ylabel
289
+ if 'axis_title_x' in gori .theme .themeables :
290
+ gori .theme .themeables ['axis_title_x' ].apply_figure (gori .figure , gori .theme .targets )
291
+ for ax in gori .axs :
292
+ gori .theme .themeables ['axis_title_x' ].apply_ax (ax )
280
293
281
- if StrictVersion (plotnine_version ) >= StrictVersion ("0.12" ):
294
+ if 'axis_title_y' in gori .theme .themeables :
295
+ gori .theme .themeables ['axis_title_y' ].apply_figure (gori .figure , gori .theme .targets )
296
+ for ax in gori .axs :
297
+ gori .theme .themeables ['axis_title_y' ].apply_ax (ax )
298
+
299
+ for key in gori .theme .themeables :
300
+ if "legend" in key :
301
+ gori .theme .themeables [key ].apply_figure (gori .figure , gori .theme .targets )
302
+ for ax in gori .axs :
303
+ gori .theme .themeables [key ].apply_ax (ax )
304
+
305
+
306
+ elif StrictVersion (plotnine_version ) >= StrictVersion ("0.12" ):
282
307
gori .theme ._targets ['axis_title_x' ] = xlabel
283
308
gori .theme ._targets ['axis_title_y' ] = ylabel
284
309
if 'axis_title_x' in gori .theme .themeables :
@@ -415,8 +440,9 @@ def draw_title(bricks, gori, gcp, figsize):
415
440
x = ha
416
441
ha = "center"
417
442
418
- except KeyError :
419
- ha = 0.5
443
+ except Exception as e :
444
+ x = 0.5
445
+ ha = "center"
420
446
421
447
try :
422
448
va = get_property ('plot_title' , 'va' )
@@ -440,7 +466,13 @@ def draw_title(bricks, gori, gcp, figsize):
440
466
else :
441
467
text = bricks ._case .set_title (title , pad = pad , fontsize = fontsize , x = x , ha = ha , va = va )
442
468
443
- if StrictVersion (plotnine_version ) >= StrictVersion ("0.12" ):
469
+ if StrictVersion (plotnine_version ) >= StrictVersion ("0.13" ):
470
+ gori .theme .targets .plot_title = text
471
+ gori .theme .themeables ['plot_title' ].apply_figure (gori .figure , gori .theme .targets )
472
+ for ax in gori .axs :
473
+ gori .theme .themeables ['plot_title' ].apply_ax (ax )
474
+
475
+ elif StrictVersion (plotnine_version ) >= StrictVersion ("0.12" ):
444
476
gori .theme ._targets ['plot_title' ] = text
445
477
gori .theme .themeables ['plot_title' ].apply_figure (gori .figure , gori .theme ._targets )
446
478
for ax in gori .axs :
@@ -487,15 +519,23 @@ def draw_title(bricks, gori, gcp, figsize):
487
519
strips = []
488
520
489
521
ggplot ._build ()
490
- axs = ggplot .facet .make_axes (
491
- _basefigure ,
492
- ggplot .layout .layout ,
493
- ggplot .coordinates )
522
+
523
+ if StrictVersion (plotnine_version ) >= StrictVersion ("0.13" ):
524
+ ggplot .facet .make_figure = mp9 .make_figure
525
+ fig , axs = plotnine .facets .facet .setup (ggplot .facet , _basefigure , ggplot )
526
+ else :
527
+ axs = ggplot .facet .make_axes (
528
+ _basefigure ,
529
+ ggplot .layout .layout ,
530
+ ggplot .coordinates )
494
531
495
532
ggplot .figure = _basefigure
496
533
ggplot .axs = axs
497
534
498
- if StrictVersion (plotnine_version ) >= StrictVersion ("0.12" ):
535
+ if StrictVersion (plotnine_version ) >= StrictVersion ("0.13" ):
536
+ ggplot .theme = gcp .theme
537
+
538
+ elif StrictVersion (plotnine_version ) >= StrictVersion ("0.12" ):
499
539
ggplot .theme = gcp .theme
500
540
ggplot .theme ._targets = gcp .theme ._targets
501
541
@@ -517,8 +557,12 @@ def draw_title(bricks, gori, gcp, figsize):
517
557
ggplot .axs [i ].spines [bar ].set_ec (gcp .axs [i ].spines [bar ].get_ec ())
518
558
ggplot .axs [i ].spines [bar ].set_visible (gcp .axs [i ].spines [bar ].get_visible ())
519
559
520
- ggplot ._setup_parameters ()
521
- ggplot .facet .strips .generate ()
560
+ if StrictVersion (plotnine_version ) >= StrictVersion ("0.13" ):
561
+ ggplot .theme .setup (ggplot )
562
+ else :
563
+ ggplot ._setup_parameters ()
564
+ ggplot .facet .strips .generate ()
565
+
522
566
for i in range (len (ggplot .facet .strips )):
523
567
if StrictVersion (plotnine_version ) >= StrictVersion ("0.12" ):
524
568
ggplot .facet .strips [i ].position = strips [i ].draw_info .position
@@ -550,6 +594,10 @@ def draw_title(bricks, gori, gcp, figsize):
550
594
for i , l in enumerate (ggplot .layers , start = 1 ):
551
595
l .zorder = i + 10
552
596
l .draw (ggplot .layout , ggplot .coordinates )
597
+
598
+ if StrictVersion (plotnine_version ) >= StrictVersion ("0.13" ):
599
+ ggplot ._draw_panel_borders ()
600
+ ggplot .facet .theme = ggplot .theme
553
601
ggplot ._draw_breaks_and_labels ()
554
602
ggplot ._draw_watermarks ()
555
603
new = themeable .from_class_name
@@ -583,7 +631,7 @@ def draw_title(bricks, gori, gcp, figsize):
583
631
584
632
if StrictVersion (plotnine_version ) >= StrictVersion ("0.9" ):
585
633
xl , yl = draw_labels (ax , ggplot , gcp , figsize )
586
- draw_legend (ax , ggplot , gcp , figsize )
634
+ draw_legend (ax , ggplot , gcp , figsize ) #0.13 makes Erros here.
587
635
draw_title (ax , ggplot , gcp , figsize )
588
636
589
637
elif StrictVersion ("0.8" ) <= StrictVersion (plotnine_version ) < StrictVersion ("0.9" ):
@@ -2449,7 +2497,7 @@ def get_outer_corner(self):
2449
2497
2450
2498
return min (x0_list ), max (x1_list ), min (y0_list ), max (y1_list )
2451
2499
2452
- def savefig (self , fname = None , transparent = None , quick = True , _ggplot = False , ** kwargs ):
2500
+ def savefig (self , fname = None , transparent = False , quick = True , _ggplot = False , ** kwargs ):
2453
2501
"""
2454
2502
2455
2503
Save figure.
@@ -2586,13 +2634,13 @@ def __sub__(self, other):
2586
2634
2587
2635
def _repr_png_ (self ):
2588
2636
buf = io .BytesIO ()
2589
- self .savefig (buf , "png" )
2637
+ self .savefig (buf , format = "png" , dpi = 300 , transparent = False )
2590
2638
return buf .getvalue ()
2591
2639
2592
- def _repr_pdf_ (self ):
2593
- buf = io .BytesIO ()
2594
- self .savefig (buf , "pdf" )
2595
- return buf .getvalue ()
2640
+ # def _repr_pdf_(self):
2641
+ # buf = io.BytesIO()
2642
+ # self.savefig(buf, format= "pdf", transparent=False )
2643
+ # return buf.getvalue()
2596
2644
2597
2645
#class Brick(axes.Axes):
2598
2646
class pBrick :
@@ -2892,7 +2940,7 @@ def get_outer_corner(self, labes=None):
2892
2940
self ._outer_flag = True
2893
2941
return self ._outer_corner
2894
2942
2895
- def savefig (self , fname = None , transparent = None , quick = True , _ggplot = False , ** kwargs ):
2943
+ def savefig (self , fname = None , transparent = False , quick = True , _ggplot = False , ** kwargs ):
2896
2944
"""
2897
2945
2898
2946
Save figure.
@@ -3078,13 +3126,13 @@ def __sub__(self, other):
3078
3126
3079
3127
def _repr_png_ (self ):
3080
3128
buf = io .BytesIO ()
3081
- self .savefig (buf , "png" )
3129
+ self .savefig (buf , format = "png" , dpi = 300 , transparent = False )
3082
3130
return buf .getvalue ()
3083
3131
3084
- def _repr_pdf_ (self ):
3085
- buf = io .BytesIO ()
3086
- self .savefig (buf , "pdf" )
3087
- return buf .getvalue ()
3132
+ # def _repr_pdf_(self):
3133
+ # buf = io.BytesIO()
3134
+ # self.savefig(buf, format= "pdf", transparent=False )
3135
+ # return buf.getvalue()
3088
3136
3089
3137
class Brick (pBrick , axes .Axes ):
3090
3138
def __getattribute__ (self , name ):
@@ -3519,4 +3567,4 @@ def resize(self, direction):
3519
3567
3520
3568
if StrictVersion (plotnine .__version__ ) >= StrictVersion ("0.12" ):
3521
3569
overwrite_plotnine ()
3522
-
3570
+
0 commit comments