Skip to content
Snippets Groups Projects
Commit 1cd9231e authored by Tobias Hangleiter's avatar Tobias Hangleiter
Browse files

Add list_styles

parent 91ee58d1
No related branches found
No related tags found
1 merge request!67Add matplotlib stylesheets
import dataclasses
import pathlib
import warnings
from contextlib import contextmanager
from typing import Sequence, Tuple, Mapping, Any, Union
from typing import Sequence, Tuple, Mapping, Any, Union, List
from weakref import WeakValueDictionary
import matplotlib as mpl
......@@ -18,6 +19,7 @@ __all__ = [
"plot_2d_dataframe",
"cycle_plots",
"update_plot",
"list_styles",
"get_rwth_color_cycle",
"rwth_color_cycle",
"rwth_color_cycle_25",
......@@ -373,6 +375,36 @@ rwth_color_cycle_100 = get_rwth_color_cycle(1)
rwth_color_cycle = rwth_color_cycle_100
def list_styles(include_matplotlib_styles: bool = False) -> List[str]:
"""List available matplotlib styles.
Parameters
----------
include_matplotlib_styles : bool, default False
Include the default styles that ship with ``matplotlib`` as well
as the custom styles in the matplotlib config directory. If
False, only the custom styles defined in this module are
listed.
Returns
-------
styles : list[str]
The styles such that ``plt.style.use(style)`` works for all
``style`` in ``styles``.
"""
custom_styles = []
root_path = pathlib.Path(__file__).parents[1]
for file in (root_path / 'plotting').glob('*.mplstyle'):
file = file.relative_to(root_path.parent)
style = '.'.join(file.parent.parts + (file.stem,))
custom_styles.append(style)
if include_matplotlib_styles:
return plt.style.available + custom_styles
else:
return custom_styles
@dataclasses.dataclass
class LaTeXPlotHelper:
A4_SIZE_INCHES = (8.25, 11.75)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment