GoogleCloudPlatform / tensorflow-without-a-phd

A crash course in six episodes for software developers who want to become machine learning practitioners.
Apache License 2.0
2.79k stars 911 forks source link

02_RNN_generator_temperatures_playground: #25

Closed SinanGabel closed 6 years ago

SinanGabel commented 6 years ago

utils_display.picture_this_4() does not run (without any changes).

I get the below error information running jupyter on Ubuntu desktop 18.04. It is the same problem with:

utils_display.picture_this_6()

By commenting out these the notebook runs without problems.

And thanks by the way for the great videos and playgrounds, they really upgrade ones neural network understanding and learning!


AttributeError Traceback (most recent call last)

in () 7 visu_dates = evdates[START_DATE:END_DATE] 8 ----> 9 utils_display.picture_this_4(visu_temperatures, visu_dates) ~/git-public/tensorflow-without-a-phd/tensorflow-rnn-tutorial/tutorial/utils_display.py in picture_this_4(temperatures, dates) 73 if interpolated_sequence: 74 # light shade of red just for visibility ---> 75 plt.axvspan(startdate+np.timedelta64(-5, 'D'), stopdate+np.timedelta64(6, 'D'), facecolor='#FFCCCC', alpha=1) 76 # actual interpolated region 77 plt.axvspan(startdate+np.timedelta64(-1, 'D'), stopdate+np.timedelta64(1, 'D'), facecolor='#FF8888', alpha=1) /usr/local/lib/python3.6/dist-packages/matplotlib/pyplot.py in axvspan(xmin, xmax, ymin, ymax, hold, **kwargs) 2753 mplDeprecation) 2754 try: -> 2755 ret = ax.axvspan(xmin, xmax, ymin=ymin, ymax=ymax, **kwargs) 2756 finally: 2757 ax._hold = washold /usr/local/lib/python3.6/dist-packages/matplotlib/axes/_axes.py in axvspan(self, xmin, xmax, ymin, ymax, **kwargs) 904 905 # first we need to strip away the units --> 906 xmin, xmax = self.convert_xunits([xmin, xmax]) 907 ymin, ymax = self.convert_yunits([ymin, ymax]) 908 /usr/local/lib/python3.6/dist-packages/matplotlib/artist.py in convert_xunits(self, x) 189 if ax is None or ax.xaxis is None: 190 return x --> 191 return ax.xaxis.convert_units(x) 192 193 def convert_yunits(self, y): /usr/local/lib/python3.6/dist-packages/matplotlib/axis.py in convert_units(self, x) 1524 return x 1525 -> 1526 ret = self.converter.convert(x, self.units, self) 1527 return ret 1528 /usr/local/lib/python3.6/dist-packages/matplotlib/dates.py in convert(value, unit, axis) 1814 The *unit* and *axis* arguments are not used. 1815 """ -> 1816 return date2num(value) 1817 1818 @staticmethod /usr/local/lib/python3.6/dist-packages/matplotlib/dates.py in date2num(d) 450 if not d.size: 451 return d --> 452 return _to_ordinalf_np_vectorized(d) 453 454 ~/.local/lib/python3.6/site-packages/numpy/lib/function_base.py in __call__(self, *args, **kwargs) 2753 vargs.extend([kwargs[_n] for _n in names]) 2754 -> 2755 return self._vectorize_call(func=func, args=vargs) 2756 2757 def _get_ufunc_and_otypes(self, func, args): ~/.local/lib/python3.6/site-packages/numpy/lib/function_base.py in _vectorize_call(self, func, args) 2823 res = func() 2824 else: -> 2825 ufunc, otypes = self._get_ufunc_and_otypes(func=func, args=args) 2826 2827 # Convert args to object arrays first ~/.local/lib/python3.6/site-packages/numpy/lib/function_base.py in _get_ufunc_and_otypes(self, func, args) 2783 2784 inputs = [arg.flat[0] for arg in args] -> 2785 outputs = func(*inputs) 2786 2787 # Performance note: profiling indicates that -- for simple /usr/local/lib/python3.6/dist-packages/matplotlib/dates.py in _to_ordinalf(dt) 253 tzi = UTC 254 --> 255 base = float(dt.toordinal()) 256 257 # If it's sufficiently datetime-like, it will have a `date()` method AttributeError: 'numpy.datetime64' object has no attribute 'toordinal'
martin-gorner commented 6 years ago

Thanks for reporting. Let me look into this. I am glad it works if you comment out the display lines but you are missing out on the visualizations.

martin-gorner commented 6 years ago

OK, I tested and the code runs perfectly for me. I am using the latest version of tensorflow and matplotlib.

martin-gorner commented 6 years ago

It looks like it is a known problem: https://stackoverflow.com/questions/47404653/pandas-0-21-0-timestamp-compatibility-issue-with-matplotlib

It appears the problem has been resolved so you should get the notebook working by upgrading to the latest version of everything.

SinanGabel commented 6 years ago

Thank you, Martin.

I first tried by updating my different software versions but that did not help but a fix from this page did it: https://github.com/matplotlib/matplotlib/issues/9610

I.e. adding the two lines after import pandas, then utils_display.picture_this_4() & _6() work.

import pandas
import pandas.plotting._converter as pandacnv
pandacnv.register()

from matplotlib import pyplot as plt

import utils_prettystyle
import utils_display