Skip to content

Commit

Permalink
Fix FutureWarning in plotting by deregistering matplotlib converters …
Browse files Browse the repository at this point in the history
…(the future behavior). Also fix bad date formatting in non-daily plot that started came with change in matplotlib default in 3.0.2
  • Loading branch information
bletham committed May 14, 2019
1 parent 73c8faf commit a087eae
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion python/fbprophet/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@

try:
from matplotlib import pyplot as plt
from matplotlib.dates import MonthLocator, num2date
from matplotlib.dates import (
MonthLocator,
num2date,
AutoDateLocator,
AutoDateFormatter,
)
from matplotlib.ticker import FuncFormatter

from pandas.plotting import deregister_matplotlib_converters
deregister_matplotlib_converters()
except ImportError:
logger.error('Importing matplotlib failed. Plotting will not work.')

Expand Down Expand Up @@ -68,6 +76,11 @@ def plot(
if uncertainty:
ax.fill_between(fcst_t, fcst['yhat_lower'], fcst['yhat_upper'],
color='#0072B2', alpha=0.2)
# Specify formatting to workaround matplotlib issue #12925
locator = AutoDateLocator(interval_multiples=False)
formatter = AutoDateFormatter(locator)
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)
ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
Expand Down Expand Up @@ -207,6 +220,11 @@ def plot_forecast_component(
artists += [ax.fill_between(
fcst_t, fcst[name + '_lower'], fcst[name + '_upper'],
color='#0072B2', alpha=0.2)]
# Specify formatting to workaround matplotlib issue #12925
locator = AutoDateLocator(interval_multiples=False)
formatter = AutoDateFormatter(locator)
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)
ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2)
ax.set_xlabel('ds')
ax.set_ylabel(name)
Expand Down

0 comments on commit a087eae

Please sign in to comment.