-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathcontext.py
More file actions
93 lines (88 loc) · 2.95 KB
/
Copy pathcontext.py
File metadata and controls
93 lines (88 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import contextlib
import warnings
from typing import Any
import matplotlib
import seaborn as sns
from pandas.plotting import (
deregister_matplotlib_converters,
register_matplotlib_converters,
)
@contextlib.contextmanager
def manage_matplotlib_context() -> Any:
"""Return a context manager for temporarily changing matplotlib unit registries and rcParams."""
originalRcParams = matplotlib.rcParams.copy()
# Credits for this style go to the ggplot and seaborn packages.
# We copied the style file to remove dependencies on the Seaborn package.
# Check it out, it's an awesome library for plotting
customRcParams = {
"patch.facecolor": "#348ABD", # blue
"patch.antialiased": True,
"font.size": 10.0,
"figure.edgecolor": "0.50",
# Seaborn common parameters
"figure.facecolor": "white",
"text.color": ".15",
"axes.labelcolor": ".15",
"legend.numpoints": 1,
"legend.scatterpoints": 1,
"xtick.direction": "out",
"ytick.direction": "out",
"xtick.color": ".15",
"ytick.color": ".15",
"axes.axisbelow": True,
"image.cmap": "Greys",
"font.family": ["sans-serif"],
"font.sans-serif": [
"IPAexGothic",
"Meiryo",
"Hiragino Sans",
"Hiragino Kaku Gothic ProN",
"Noto Sans CJK JP",
"IPAGothic",
"Arial",
"Liberation Sans",
"Bitstream Vera Sans",
"sans-serif",
],
"grid.linestyle": "-",
"lines.solid_capstyle": "round",
# Seaborn darkgrid parameters
# .15 = dark_gray
# .8 = light_gray
"axes.grid": True,
"axes.facecolor": "#EAEAF2",
"axes.edgecolor": "white",
"axes.linewidth": 0,
"grid.color": "white",
# Seaborn notebook context
"figure.figsize": [8.0, 5.5],
"axes.labelsize": 11,
"axes.titlesize": 12,
"xtick.labelsize": 10,
"ytick.labelsize": 10,
"legend.fontsize": 10,
"grid.linewidth": 1,
"lines.linewidth": 1.75,
"patch.linewidth": 0.3,
"lines.markersize": 7,
"lines.markeredgewidth": 0,
"xtick.major.width": 1,
"ytick.major.width": 1,
"xtick.minor.width": 0.5,
"ytick.minor.width": 0.5,
"xtick.major.pad": 7,
"ytick.major.pad": 7,
"backend": "agg",
}
try:
register_matplotlib_converters()
sns.set_style(style="white")
matplotlib.rcParams.update(customRcParams)
yield
finally:
deregister_matplotlib_converters() # revert to original unit registries
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", category=matplotlib.MatplotlibDeprecationWarning
)
matplotlib.rcParams.update(originalRcParams) # revert to original rcParams