Screen Link:
Need help figuring out the error.
As soon as I uncomment the "#x = 13110
#for year in [‘2006’, ‘2007’, ‘2008’, ‘2009’, ‘2010’]:
ax.text(x, 1.13, year, alpha=0.5, fontsize=11)
x += 365" I get the error.
I also got an error when using numbers instead of dates in the axvspan.
The code is obviously from the solution.
There is something I am not getting right.
Really need to understand what is going on to progress.
My Code:
import matplotlib.style as style
style.use('fivethirtyeight')
from datetime import datetime
### Adding the plot
fig,ax = plt.subplots(figsize=(8,3))
ax.plot(rate2006_2009['Time'],
rate2006_2009['rolling_mean'],
linewidth=1, color='#A6D785')
### Highlighting the 2007-2008 period
ax.plot(GFC2008['Time'],
GFC2008['rolling_mean'],
linewidth=3, color='#e23d28')
### Highlihting the peak of the crisis
ax.axvspan(xmin=(datetime(2008,6,1)),
xmax=(datetime(2007,5,30)),
ymin=0.02, alpha=0.3, color='grey')
### Adding separate tick labels
ax.set_xticklabels([])
ax.set_yticklabels([])
#x = 13110
#for year in ['2006', '2007', '2008', '2009', '2010']:
# ax.text(x, 1.13, year, alpha=0.5, fontsize=11)
# x += 365
#y = 1.193
#for rate in ['1.2', '1.3', '1.4', '1.5']:
# ax.text(13020, y, rate, alpha=0.5, fontsize=11)
# y += 0.1
### Adding a title and a subtitle
#ax.text(13020, 1.67, "Euro-USD rate peaked at 1.59 during 2007-2008's financial crisis",
# weight='bold')
#ax.text(13020, 1.63, 'Euro-USD exchange rates between 2006 and 2010',
# size=12)
### Adding a signature
#ax.text(13020, 1.07, '©DATAQUEST' + ' '*94 + 'Source: European Central Bank',
# color = '#f0f0f0', backgroundcolor = '#4d4d4d',
# size=10)
### Add some transparency to the grid
#ax.grid(alpha=0.5)
plt.show()
What I expected to happen:
What actually happened:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/dataquest/system/env/python3/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj)
339 pass
340 else:
--> 341 return printer(obj)
342 # Finally look for special method names
343 method = get_real_method(obj, self.print_method)
/dataquest/system/env/python3/lib/python3.8/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
246
247 if 'png' in formats:
--> 248 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
249 if 'retina' in formats or 'png2x' in formats:
250 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
/dataquest/system/env/python3/lib/python3.8/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
130 FigureCanvasBase(fig)
131
--> 132 fig.canvas.print_figure(bytes_io, **kw)
133 data = bytes_io.getvalue()
134 if fmt == 'svg':
/dataquest/system/env/python3/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, **kwargs)
2117
2118 try:
-> 2119 result = print_method(
2120 filename,
2121 dpi=dpi,
/dataquest/system/env/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args, **kwargs)
512 }
513
--> 514 FigureCanvasAgg.draw(self)
515 if pil_kwargs is not None:
516 from PIL import Image
/dataquest/system/env/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in draw(self)
386 Draw the figure using the renderer.
387 """
--> 388 self.renderer = self.get_renderer(cleared=True)
389 # Acquire a lock on the shared font cache.
390 with RendererAgg.lock, \
/dataquest/system/env/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in get_renderer(self, cleared)
402 and getattr(self, "_lastKey", None) == key)
403 if not reuse_renderer:
--> 404 self.renderer = RendererAgg(w, h, self.figure.dpi)
405 self._lastKey = key
406 elif cleared:
/dataquest/system/env/python3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in __init__(self, width, height, dpi)
90 self.width = width
91 self.height = height
---> 92 self._renderer = _RendererAgg(int(width), int(height), dpi)
93 self._filter_renderers = []
94
ValueError: Image size of 312582x284 pixels is too large. It must be less than 2^16 in each direction.
<Figure size 800x300 with 1 Axes>