|
20 | 20 |
|
21 | 21 | try: |
22 | 22 | 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 | + ) |
24 | 29 | from matplotlib.ticker import FuncFormatter |
| 30 | + |
| 31 | + from pandas.plotting import deregister_matplotlib_converters |
| 32 | + deregister_matplotlib_converters() |
25 | 33 | except ImportError: |
26 | 34 | logger.error('Importing matplotlib failed. Plotting will not work.') |
27 | 35 |
|
@@ -68,6 +76,11 @@ def plot( |
68 | 76 | if uncertainty: |
69 | 77 | ax.fill_between(fcst_t, fcst['yhat_lower'], fcst['yhat_upper'], |
70 | 78 | 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) |
71 | 84 | ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2) |
72 | 85 | ax.set_xlabel(xlabel) |
73 | 86 | ax.set_ylabel(ylabel) |
@@ -207,6 +220,11 @@ def plot_forecast_component( |
207 | 220 | artists += [ax.fill_between( |
208 | 221 | fcst_t, fcst[name + '_lower'], fcst[name + '_upper'], |
209 | 222 | 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) |
210 | 228 | ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2) |
211 | 229 | ax.set_xlabel('ds') |
212 | 230 | ax.set_ylabel(name) |
|
0 commit comments