55
66import matplotlib .pyplot as plt
77
8- from fooof .plts .settings import AXIS_STYLE_ARGS , LINE_STYLE_ARGS , CUSTOM_STYLE_ARGS , STYLE_ARGS
9- from fooof . plts . settings import ( LABEL_SIZE , LEGEND_SIZE , LEGEND_LOC ,
10- TICK_LABELSIZE , TITLE_FONTSIZE )
8+ from fooof .plts .settings import ( AXIS_STYLE_ARGS , LINE_STYLE_ARGS , COLLECTION_STYLE_ARGS ,
9+ CUSTOM_STYLE_ARGS , STYLE_ARGS , LABEL_SIZE , LEGEND_SIZE ,
10+ LEGEND_LOC , TICK_LABELSIZE , TITLE_FONTSIZE )
1111
1212###################################################################################################
1313###################################################################################################
@@ -119,6 +119,27 @@ def apply_line_style(ax, style_args=LINE_STYLE_ARGS, **kwargs):
119119 line .set (** {style : next (values )})
120120
121121
122+ def apply_collection_style (ax , style_args = COLLECTION_STYLE_ARGS , ** kwargs ):
123+ """Apply collection plot style.
124+
125+ Parameters
126+ ----------
127+ ax : matplotlib.Axes
128+ Figure axes to apply style to.
129+ style_args : list of str
130+ A list of arguments to be sub-selected from `kwargs` and applied as collection styling.
131+ **kwargs
132+ Keyword arguments that define collection style to apply.
133+ """
134+
135+ # Get the collection related styling arguments from the keyword arguments
136+ collection_kwargs = {key : val for key , val in kwargs .items () if key in style_args }
137+
138+ # Apply any provided collection style arguments
139+ for collection in ax .collections :
140+ collection .set (** collection_kwargs )
141+
142+
122143def apply_custom_style (ax , ** kwargs ):
123144 """Apply custom plot style.
124145
@@ -152,14 +173,15 @@ def apply_custom_style(ax, **kwargs):
152173
153174
154175def apply_style (ax , axis_styler = apply_axis_style , line_styler = apply_line_style ,
155- custom_styler = apply_custom_style , ** kwargs ):
176+ collection_styler = apply_collection_style , custom_styler = apply_custom_style ,
177+ ** kwargs ):
156178 """Apply plot style to a figure axis.
157179
158180 Parameters
159181 ----------
160182 ax : matplotlib.Axes
161183 Figure axes to apply style to.
162- axis_styler, line_styler, custom_styler : callable, optional
184+ axis_styler, line_styler, collection_style, custom_styler : callable, optional
163185 Functions to apply style to aspects of the plot.
164186 **kwargs
165187 Keyword arguments that define style to apply.
@@ -172,6 +194,7 @@ def apply_style(ax, axis_styler=apply_axis_style, line_styler=apply_line_style,
172194
173195 axis_styler (ax , ** kwargs )
174196 line_styler (ax , ** kwargs )
197+ collection_styler (ax , ** kwargs )
175198 custom_styler (ax , ** kwargs )
176199
177200
0 commit comments