diff --git a/changelog_entry.yaml b/changelog_entry.yaml index e69de29..c5ad5b6 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -0,0 +1,4 @@ +- bump: patch + changes: + changed: + - Deleted visualization functionality. diff --git a/docs/demo.ipynb b/docs/demo.ipynb index 06ecd46..b9d10f1 100644 --- a/docs/demo.ipynb +++ b/docs/demo.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -24,11 +24,7 @@ "import pandas as pd\n", "\n", "import taxcalc as tc\n", - "import microdf as mdf\n", - "\n", - "import matplotlib as mpl\n", - "import matplotlib.pyplot as plt\n", - "import seaborn as sns" + "import microdf as mdf" ] }, { diff --git a/microdf/__init__.py b/microdf/__init__.py index d2b9791..aede573 100644 --- a/microdf/__init__.py +++ b/microdf/__init__.py @@ -1,6 +1,4 @@ from .agg import agg, combine_base_reform, pctchg_base_reform -from .chart_utils import currency_format, dollar_format -from .charts import quantile_pct_chg_plot from .concat import concat from .constants import ( BENS, @@ -47,7 +45,6 @@ poverty_rate, squared_poverty_gap, ) -from .style import AXIS_COLOR, DPI, GRID_COLOR, TITLE_COLOR, set_plot_style from .tax import mtr, tax_from_mtrs from .taxcalc import ( add_weighted_metrics, diff --git a/microdf/chart_utils.py b/microdf/chart_utils.py deleted file mode 100644 index bb96c43..0000000 --- a/microdf/chart_utils.py +++ /dev/null @@ -1,37 +0,0 @@ -from typing import Optional - -from matplotlib.ticker import FuncFormatter - - -def dollar_format(suffix: Optional[str] = "") -> "FuncFormatter": - """Dollar formatter for matplotlib. - - :param suffix: Suffix to append, e.g. 'B'. Defaults to ''. - :returns: FuncFormatter. - """ - return currency_format(currency="USD", suffix=suffix) - - -def currency_format( - currency: Optional[str] = "USD", suffix: Optional[str] = "" -) -> "FuncFormatter": - """Currency formatter for matplotlib. - - :param currency: Name of the currency, e.g. 'USD', 'GBP'. - :param suffix: Suffix to append, e.g. 'B'. Defaults to ''. - :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] - - return mpl.ticker.FuncFormatter( - lambda x, _: prefix + format(int(x), ",") + suffix - ) diff --git a/microdf/charts.py b/microdf/charts.py deleted file mode 100644 index 6f168d7..0000000 --- a/microdf/charts.py +++ /dev/null @@ -1,62 +0,0 @@ -import numpy as np -import pandas as pd - -import microdf as mdf - - -def quantile_pct_chg_plot( - df1: pd.DataFrame, - df2: pd.DataFrame, - col1: str, - col2: str, - w1: str = None, - w2: str = None, - q: np.ndarray = None, -): - """Create stem plot with percent change in decile boundaries. - - :param df1: DataFrame with first set of values. - :param df2: DataFrame with second set of values. - :param col1: Name of columns with values in df1. - :param col2: Name of columns with values in df2. - :param w1: Name of weight column in df1. - :param w2: Name of weight column in df2. - :param q: Quantiles. Defaults to decile boundaries. - :returns: Axis. - """ - try: - import matplotlib as mpl - import matplotlib.pyplot as plt - import seaborn as sns - 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]'" - ) - - if q is None: - q = np.arange(0.1, 1, 0.1) - # Calculate weighted quantiles. - df = mdf.quantile_chg(df1, df2, col1, col2, w1, w2, q).transpose() - # Prepare dataset for plotting. - df.columns = ["base", "reform"] - df["pct_chg"] = df.reform / df.base - 1 - # Multiply by 100 pending github.com/matplotlib/matplotlib/issues/17113 - df.pct_chg *= 100 - df["index_newline"] = np.where( - df.index == "50th (median)", "50th\n(median)", df.index - ) - # Plot. - fig, ax = plt.subplots() - markerline, stemlines, baseline = ax.stem(df.index_newline, df.pct_chg) - plt.setp(baseline, color="gray", linewidth=0) - ax.yaxis.set_major_locator(mpl.ticker.MaxNLocator(integer=True)) - ax.yaxis.set_major_formatter(mpl.ticker.PercentFormatter(xmax=100)) - plt.title("Change to percentiles", loc="left") - plt.ylabel("Change at the percentile boundary") - plt.xlabel("Percentile") - sns.despine(left=True, bottom=True) - ax.grid(color=mdf.GRID_COLOR, axis="y") - plt.xticks(rotation=0) - return ax diff --git a/microdf/style.py b/microdf/style.py deleted file mode 100644 index 68bfb40..0000000 --- a/microdf/style.py +++ /dev/null @@ -1,54 +0,0 @@ -TITLE_COLOR = "#212121" -AXIS_COLOR = "#757575" -GRID_COLOR = "#eeeeee" # Previously lighter #f5f5f5. -DPI = 200 - - -def set_plot_style(dpi: int = DPI) -> None: - """Set plot style. - - :param dpi: DPI for saving and displaying figures, defaults to microdf.DPI - (200). - :type dpi: int, optional - """ - try: - import matplotlib as mpl - import matplotlib.font_manager as fm - import seaborn as sns - 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]'" - ) - - sns.set_style("white") - - # Set up Roboto. Must be downloaded in the current directory. - # See https://stackoverflow.com/a/51844978/1840471. - fm.fontManager.ttflist += fm.createFontList(["Roboto-Regular.ttf"]) - - STYLE = { - "savefig.dpi": dpi, - "figure.dpi": dpi, - "figure.figsize": (6.4, 4.8), # Default. - "font.sans-serif": "Roboto", - "font.family": "sans-serif", - # Set title text color to dark gray (https://material.io/color) not - # black. - "text.color": TITLE_COLOR, - # Axis titles and tick marks are medium gray. - "axes.labelcolor": AXIS_COLOR, - "xtick.color": AXIS_COLOR, - "ytick.color": AXIS_COLOR, - # Grid is light gray. - "axes.grid": True, - "grid.color": GRID_COLOR, - # Equivalent to seaborn.despine(left=True, bottom=True). - "axes.spines.left": False, - "axes.spines.right": False, - "axes.spines.top": False, - "axes.spines.bottom": False, - } - - mpl.rcParams.update(STYLE) diff --git a/microdf/tests/test_quantile_chg.py b/microdf/tests/test_quantile_chg.py index 7d9e830..bd77844 100644 --- a/microdf/tests/test_quantile_chg.py +++ b/microdf/tests/test_quantile_chg.py @@ -12,7 +12,3 @@ def test_quantile_chg() -> None: mdf.quantile_chg(DF1, DF2, "v", "w", "v", "w") - - -def test_quantile_pct_chg_plot() -> None: - mdf.quantile_pct_chg_plot(DF1, DF2, "v", "w", "v", "w") diff --git a/pyproject.toml b/pyproject.toml index 4c616db..9606395 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,8 +3,8 @@ requires = ["setuptools>=61.0", "wheel"] build-backend = "setuptools.build_meta" [project] -name = "microdf-python" -version = "0.4.6" +name = "microdf" +version = "0.4.5" description = "Survey microdata as DataFrames" readme = "README.md" authors = [ @@ -26,13 +26,10 @@ dev = [ "docformatter", "isort", "linecheck", - "matplotlib", "pip", "pytest", "pytest-cov", - "seaborn", "setuptools", - "build", ] docs = [ "jupyter_book", @@ -40,11 +37,6 @@ docs = [ taxcalc = [ "taxcalc", ] -charts = [ - "seaborn", - "matplotlib", - "matplotlib-label-lines", -] [tool.setuptools.packages.find] where = ["."]