Fix missing m/d on trend component plot. Previously we used MaxNLocator to limit the number of tick marks on the trend and holiday component plots. This was putting the ticks at various points throughout the year, however the tick label showed only the year, which one would incorrectly assume to be Jan 1. This commit removes MaxNLocator and allows matplotlib to set xticks as it pleases, and updates the effected documentation.

This commit is contained in:
Ben Letham 2017-03-16 15:43:16 +02:00
parent 218455c06b
commit 2c8419e673
7 changed files with 47 additions and 50 deletions

View file

@ -148,36 +148,36 @@ forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
<th>3265</th> <th>3265</th>
<td>2017-01-15</td> <td>2017-01-15</td>
<td>8.205065</td> <td>8.205065</td>
<td>7.518780</td> <td>7.488507</td>
<td>8.899184</td> <td>8.887731</td>
</tr> </tr>
<tr> <tr>
<th>3266</th> <th>3266</th>
<td>2017-01-16</td> <td>2017-01-16</td>
<td>8.530088</td> <td>8.530088</td>
<td>7.752344</td> <td>7.862778</td>
<td>9.246332</td> <td>9.223688</td>
</tr> </tr>
<tr> <tr>
<th>3267</th> <th>3267</th>
<td>2017-01-17</td> <td>2017-01-17</td>
<td>8.317468</td> <td>8.317468</td>
<td>7.641099</td> <td>7.644606</td>
<td>9.039998</td> <td>9.021893</td>
</tr> </tr>
<tr> <tr>
<th>3268</th> <th>3268</th>
<td>2017-01-18</td> <td>2017-01-18</td>
<td>8.150081</td> <td>8.150081</td>
<td>7.333512</td> <td>7.462394</td>
<td>8.888837</td> <td>8.889095</td>
</tr> </tr>
<tr> <tr>
<th>3269</th> <th>3269</th>
<td>2017-01-19</td> <td>2017-01-19</td>
<td>8.162015</td> <td>8.162015</td>
<td>7.415570</td> <td>7.438503</td>
<td>8.850360</td> <td>8.877361</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -236,12 +236,12 @@ tail(future)
``` ```
ds ds
3264 2017-01-13
3265 2017-01-14 3265 2017-01-14
3266 2017-01-15 3266 2017-01-15
3267 2017-01-16 3267 2017-01-16
3268 2017-01-17 3268 2017-01-17
3269 2017-01-18 3269 2017-01-18
3270 2017-01-19
@ -254,12 +254,12 @@ tail(forecast[c('ds', 'yhat', 'yhat_lower', 'yhat_upper')])
``` ```
ds yhat yhat_lower yhat_upper ds yhat yhat_lower yhat_upper
3264 2017-01-13 8.052054 7.328934 8.845277 3265 2017-01-14 7.832396 7.140713 8.533132
3265 2017-01-14 7.832396 7.147092 8.515437 3266 2017-01-15 8.214232 7.460897 8.918678
3266 2017-01-15 8.214232 7.439343 8.947970 3267 2017-01-16 8.539239 7.788240 9.262142
3267 2017-01-16 8.539239 7.804152 9.243396 3268 2017-01-17 8.326654 7.615613 9.003147
3268 2017-01-17 8.326654 7.635376 9.036896 3269 2017-01-18 8.159337 7.382162 8.889958
3269 2017-01-18 8.159337 7.445167 8.907354 3270 2017-01-19 8.171276 7.354854 8.922918

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 42 KiB

File diff suppressed because one or more lines are too long

View file

@ -16,7 +16,6 @@ import pickle
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from matplotlib.dates import DateFormatter, MonthLocator from matplotlib.dates import DateFormatter, MonthLocator
from matplotlib.ticker import MaxNLocator
import numpy as np import numpy as np
import pandas as pd import pandas as pd
@ -712,7 +711,6 @@ class Prophet(object):
fcst['ds'].values, fcst['trend_lower'], fcst['trend_upper'], fcst['ds'].values, fcst['trend_lower'], fcst['trend_upper'],
color='#0072B2', alpha=0.2)] color='#0072B2', alpha=0.2)]
ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2) ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2)
ax.xaxis.set_major_locator(MaxNLocator(nbins=7))
ax.set_xlabel('ds') ax.set_xlabel('ds')
ax.set_ylabel('trend') ax.set_ylabel('trend')
return artists return artists
@ -749,7 +747,6 @@ class Prophet(object):
y_holiday_l, y_holiday_u, y_holiday_l, y_holiday_u,
color='#0072B2', alpha=0.2)] color='#0072B2', alpha=0.2)]
ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2) ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2)
ax.xaxis.set_major_locator(MaxNLocator(nbins=7))
ax.set_xlabel('ds') ax.set_xlabel('ds')
ax.set_ylabel('holidays') ax.set_ylabel('holidays')
return artists return artists