File tree Expand file tree Collapse file tree 2 files changed +15
-11
lines changed Expand file tree Collapse file tree 2 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -24,17 +24,13 @@ class plot_context:
24
24
"""
25
25
26
26
def __init__ (self , plot : ggplot , show : bool = False ):
27
- self .plot = plot
28
- self .show = show
29
-
30
- def __enter__ (self ) -> Self :
31
- """
32
- Enclose in matplolib & pandas environments
33
- """
34
27
import matplotlib as mpl
35
28
36
- self .rc_context = mpl .rc_context (self .plot .theme .rcParams )
29
+ self .plot = plot
30
+ self .show = show
37
31
32
+ # Contexts
33
+ self .rc_context = mpl .rc_context (plot .theme .rcParams )
38
34
# Pandas deprecated is_copy, and when we create new dataframes
39
35
# from slices we do not want complaints. We always uses the
40
36
# new frames knowing that they are separate from the original.
@@ -44,6 +40,11 @@ def __enter__(self) -> Self:
44
40
"mode.copy_on_write" ,
45
41
False ,
46
42
)
43
+
44
+ def __enter__ (self ) -> Self :
45
+ """
46
+ Enclose in matplolib & pandas environments
47
+ """
47
48
self .rc_context .__enter__ ()
48
49
self .pd_option_context .__enter__ ()
49
50
return self
Original file line number Diff line number Diff line change @@ -672,7 +672,9 @@ def save(
672
672
verbose = verbose ,
673
673
** kwargs ,
674
674
)
675
- sv .figure .savefig (** sv .kwargs )
675
+
676
+ with plot_context (self ).rc_context :
677
+ sv .figure .savefig (** sv .kwargs )
676
678
677
679
678
680
ggsave = ggplot .save
@@ -780,5 +782,6 @@ def facet_pages(column)
780
782
# Re-add the first element to the iterator, if it was removed
781
783
for plot in plots :
782
784
fig = plot .draw ()
783
- # Save as a page in the PDF file
784
- pdf .savefig (fig , ** fig_kwargs )
785
+ with plot_context (plot ).rc_context :
786
+ # Save as a page in the PDF file
787
+ pdf .savefig (fig , ** fig_kwargs )
You can’t perform that action at this time.
0 commit comments