Skip to content

Commit

Permalink
Merge pull request #222 from MaxGhenis/labellines
Browse files Browse the repository at this point in the history
Remove quantile_chg_plot to drop matplotlib-label-lines dep
  • Loading branch information
MaxGhenis committed Jul 1, 2021
2 parents c74ebe9 + cce49eb commit 85d2739
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 94 deletions.
30 changes: 1 addition & 29 deletions docs/demo.ipynb

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ dependencies:
- seaborn
- setuptools
- pip:
- matplotlib-label-lines
- jupyter-book
3 changes: 1 addition & 2 deletions microdf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .agg import agg, combine_base_reform, pctchg_base_reform
from .chart_utils import dollar_format, currency_format
from .charts import quantile_chg_plot, quantile_pct_chg_plot
from .charts import quantile_pct_chg_plot
from .concat import concat
from .constants import (
BENS,
Expand Down Expand Up @@ -86,7 +86,6 @@
"dollar_format",
"currency_format",
# charts.py
"quantile_chg_plot",
"quantile_pct_chg_plot",
# concat.py
"concat",
Expand Down
58 changes: 0 additions & 58 deletions microdf/charts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import labellines as ll
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -7,63 +6,6 @@
import microdf as mdf


def quantile_chg_plot(
df1,
df2,
col1,
col2,
w1=None,
w2=None,
q=None,
label1="Base",
label2="Reform",
title="Change in disposable income percentiles",
currency="USD",
):
"""Create plot with one line per quantile boundary between base and
reform.
: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.
:param label1: Label for left side of x-axis. Defaults to 'Base'.
:param label2: Label for right side of x-axis. Defaults to 'Reform'.
:returns: Axis.
"""
# Calculate the q default because it's later used for defining a color
# palette.
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)
# Make shades of green, removing the lightest 10 shades.
with sns.color_palette(sns.color_palette("Greens", q.size + 11)[11:]):
ax = df.plot()
# Label the start and end points.
plt.xticks([0, 1], [label1, label2])
# Label the lines instead of using a legend.
ax.get_legend().remove()
# Move line labels closer to the center.
ll.labelLines(plt.gca().get_lines(), xvals=(0.1, 0.9))
# Formatting.
plt.title(title)
plt.ylim(0, None)
ax.grid(color=mdf.GRID_COLOR, axis="y")
formatter = mdf.currency_format(currency)
ax.yaxis.set_major_formatter(formatter)
ax.yaxis.set_minor_formatter(formatter)
sns.despine(left=True, bottom=True)
ax.axhline(0, color="lightgray", zorder=-1)
# Looks better narrower.
plt.gcf().set_size_inches(4, 6)
return ax


def quantile_pct_chg_plot(df1, df2, col1, col2, w1=None, w2=None, q=None):
"""Create stem plot with percent change in decile boundaries.
Expand Down
4 changes: 0 additions & 4 deletions microdf/tests/test_quantile_chg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,5 @@ def test_quantile_chg():
mdf.quantile_chg(DF1, DF2, "v", "w", "v", "w")


def test_quantile_chg_plot():
mdf.quantile_chg_plot(DF1, DF2, "v", "w", "v", "w")


def test_quantile_pct_chg_plot():
mdf.quantile_pct_chg_plot(DF1, DF2, "v", "w", "v", "w")

0 comments on commit 85d2739

Please sign in to comment.