Skip to content

Commit

Permalink
fix: Conditionally import matplotlib
Browse files Browse the repository at this point in the history
  • Loading branch information
anth-volk committed Oct 24, 2024
1 parent eeab81a commit 65455ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
9 changes: 6 additions & 3 deletions microdf/chart_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import matplotlib as mpl


def dollar_format(suffix=""):
"""Dollar formatter for matplotlib.
Expand All @@ -19,6 +16,12 @@ def currency_format(currency="USD", suffix=""):
:returns: FuncFormatter.
"""
try:
import matplotlib as mpl
except ImportError:
raise ImportError(
"The function you've called requires extra dependencies. Please install microdf with the 'charts' extra by running 'pip install microdf[charts]'"
)

prefix = {"USD": "$", "GBP": "£"}[currency]

Expand Down
4 changes: 2 additions & 2 deletions microdf/charts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

import microdf as mdf
Expand All @@ -20,6 +18,8 @@ def quantile_pct_chg_plot(df1, df2, col1, col2, w1=None, w2=None, q=None):
"""
try:
import seaborn as sns
import matplotlib as mpl
import matplotlib.pyplot as plt
except ImportError:
raise ImportError(
"The function you've called requires extra dependencies. Please install microdf with the 'charts' extra by running 'pip install microdf[charts]'"
Expand Down
6 changes: 2 additions & 4 deletions microdf/style.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import matplotlib as mpl
import matplotlib.font_manager as fm


TITLE_COLOR = "#212121"
AXIS_COLOR = "#757575"
GRID_COLOR = "#eeeeee" # Previously lighter #f5f5f5.
Expand All @@ -17,6 +13,8 @@ def set_plot_style(dpi: int = DPI):
"""
try:
import seaborn as sns
import matplotlib as mpl
import matplotlib.font_manager as fm
except ImportError:
raise ImportError(
"The function you've called requires extra dependencies. Please install microdf with the 'charts' extra by running 'pip install microdf[charts]'"
Expand Down

0 comments on commit 65455ec

Please sign in to comment.