Skip to content

Commit

Permalink
update(styles): add graph_legend fontsize parameters (#1702)
Browse files Browse the repository at this point in the history
* add fontsize argument to graph_legend_title
* add fontsize and title_fontsize kwargs to graph_legend
  • Loading branch information
jlarsen-usgs committed Feb 7, 2023
1 parent 3b2800e commit 2552de5
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions flopy/plot/styles.py
Expand Up @@ -210,22 +210,23 @@ def graph_legend(cls, ax=None, handles=None, labels=None, **kwargs):
if ax is None:
ax = plt.gca()

fontspec = styles.__set_fontspec(bold=True, italic=False, family=True)
fontsize = kwargs.pop("fontsize", 9)
fontspec = styles.__set_fontspec(
bold=True, italic=False, family=True, fontsize=fontsize
)

if handles is None or labels is None:
handles, labels = ax.get_legend_handles_labels()
leg = ax.legend(handles, labels, prop=fontspec, **kwargs)

# add title to legend
if "title" in kwargs:
title = kwargs.pop("title")
else:
title = None
title = kwargs.pop("title", None)
fontsize = kwargs.pop("title_fontsize", None)

leg = styles.graph_legend_title(leg, title=title)
return leg

@classmethod
def graph_legend_title(cls, leg, title=None):
def graph_legend_title(cls, leg, title=None, fontsize=9):
"""Set the legend title for a matplotlib legend object
Parameters
Expand All @@ -234,6 +235,8 @@ def graph_legend_title(cls, leg, title=None):
matplotlib legend object
title : str
title for legend
fontsize : int
fontsize for legend
Returns
-------
Expand All @@ -246,7 +249,9 @@ def graph_legend_title(cls, leg, title=None):
elif title.lower() == "none":
title = None

fontspec = styles.__set_fontspec(bold=True, italic=False, family=True)
fontspec = styles.__set_fontspec(
bold=True, italic=False, family=True, fontsize=fontsize
)

leg.set_title(title, prop=fontspec)
return leg
Expand Down

0 comments on commit 2552de5

Please sign in to comment.