0

I'm getting the following error somewhere in this code block:

ValueError: view limit minimum -34780.4 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime units

I know this code is causing it because I'm running it in blocks on Google Colab:

from pylab import rcParams
rcParams['figure.figsize'] = 14, 5

# Plot parameters
START_DATE_FOR_PLOTTING = '2012-01-14'

plt.plot(PREDICTIONS_FUTURE.index, PREDICTIONS_FUTURE['Open'], color='r', label='Predicted Stock Price')
plt.plot(dataset_train.loc[START_DATE_FOR_PLOTTING:].index, dataset_train.loc[START_DATE_FOR_PLOTTING:]['Open'], color='b', label='Actual Stock Price')

plt.axvline(x = min(PREDICTIONS_FUTURE.index), color='green', linewidth=2, linestyle='--')

plt.grid(which='major', color='#cccccc', alpha=0.5)

plt.legend(shadow=True)
plt.title('Predcitions and Acutal Stock Prices', family='Arial', fontsize=12)
plt.xlabel('Timeline', family='Arial', fontsize=10)
plt.ylabel('Stock Price Value', family='Arial', fontsize=10)
plt.xticks(rotation=45, fontsize=8)
plt.show()

dataset_train = pd.DataFrame(dataset_train, columns=cols)
dataset_train.index = datelist_train
dataset_train.index = pd.to_datetime(dataset_train.index)

I checked the CSV I'm using for any strange values in the date column but found nothing.

EDIT: according to the traceback it's this line causing the problem:

plt.xticks(rotation=45, fontsize=8)

MJ95
  • 459
  • 1
  • 6
  • 22
  • `This often happens if you pass a non-datetime value to an axis that has datetime units` - have you checked if this is the reason? – mkrieger1 Feb 05 '21 at 01:10
  • *"I'm getting the following Error somewhere in this code block"* - the error message should contain a traceback that tells you where *exactly* the error occurs. – mkrieger1 Feb 05 '21 at 01:11
  • @mkrieger1 just added the exact line and yes, I don't see any non-datetime values that I'm passing – MJ95 Feb 05 '21 at 01:15
  • Can you please show the full traceback? – mkrieger1 Feb 05 '21 at 01:17
  • I just wanted to and in running it again I can no longer reproduce, very strange – MJ95 Feb 05 '21 at 01:24

0 Answers0