Skip to content

Commit a087eae

Browse files
committed
Fix FutureWarning in plotting by deregistering matplotlib converters (the future behavior). Also fix bad date formatting in non-daily plot that started came with change in matplotlib default in 3.0.2
1 parent 73c8faf commit a087eae

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

python/fbprophet/plot.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@
2020

2121
try:
2222
from matplotlib import pyplot as plt
23-
from matplotlib.dates import MonthLocator, num2date
23+
from matplotlib.dates import (
24+
MonthLocator,
25+
num2date,
26+
AutoDateLocator,
27+
AutoDateFormatter,
28+
)
2429
from matplotlib.ticker import FuncFormatter
30+
31+
from pandas.plotting import deregister_matplotlib_converters
32+
deregister_matplotlib_converters()
2533
except ImportError:
2634
logger.error('Importing matplotlib failed. Plotting will not work.')
2735

@@ -68,6 +76,11 @@ def plot(
6876
if uncertainty:
6977
ax.fill_between(fcst_t, fcst['yhat_lower'], fcst['yhat_upper'],
7078
color='#0072B2', alpha=0.2)
79+
# Specify formatting to workaround matplotlib issue #12925
80+
locator = AutoDateLocator(interval_multiples=False)
81+
formatter = AutoDateFormatter(locator)
82+
ax.xaxis.set_major_locator(locator)
83+
ax.xaxis.set_major_formatter(formatter)
7184
ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2)
7285
ax.set_xlabel(xlabel)
7386
ax.set_ylabel(ylabel)
@@ -207,6 +220,11 @@ def plot_forecast_component(
207220
artists += [ax.fill_between(
208221
fcst_t, fcst[name + '_lower'], fcst[name + '_upper'],
209222
color='#0072B2', alpha=0.2)]
223+
# Specify formatting to workaround matplotlib issue #12925
224+
locator = AutoDateLocator(interval_multiples=False)
225+
formatter = AutoDateFormatter(locator)
226+
ax.xaxis.set_major_locator(locator)
227+
ax.xaxis.set_major_formatter(formatter)
210228
ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2)
211229
ax.set_xlabel('ds')
212230
ax.set_ylabel(name)

0 commit comments

Comments
 (0)