-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9710538
commit ae3f400
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# From https://github.com/garrettj403/SciencePlots/blob/master/scienceplots/__init__.py | ||
from os import listdir | ||
from os.path import isdir, join | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
import lovelyplots | ||
|
||
# register the included stylesheet in the matplotlib style library | ||
lovelyplots_path = lovelyplots.__path__[0] | ||
styles_path = join(lovelyplots_path, 'styles') | ||
|
||
# Reads styles in /styles | ||
stylesheets = plt.style.core.read_style_directory(styles_path) | ||
# Reads styles in /styles subfolders | ||
for inode in listdir(styles_path): | ||
new_data_path = join(styles_path, inode) | ||
if isdir(new_data_path): | ||
new_stylesheets = plt.style.core.read_style_directory(new_data_path) | ||
stylesheets.update(new_stylesheets) | ||
|
||
# Update dictionary of styles | ||
plt.style.core.update_nested_dict(plt.style.library, stylesheets) | ||
# Update `plt.style.available`, copy-paste from: | ||
# https://github.com/matplotlib/matplotlib/blob/a170539a421623bb2967a45a24bb7926e2feb542/lib/matplotlib/style/core.py#L266 | ||
plt.style.core.available[:] = sorted(plt.style.library.keys()) |