-
Notifications
You must be signed in to change notification settings - Fork 102
Closed
Labels
Milestone
Description
Description
Some geographic plots cannot be plotted due to the image size being too large. This happens when a colorbar
is plotted with pcolormesh
. It works when the image is plotted with contourf
.
Steps to reproduce
import numpy as np
import xarray as xr
import proplot as plot
rng = np.random.default_rng()
x = rng.standard_normal((100, 100))
da = xr.DataArray(x,
dims=['lat', 'lon'],
coords={'lat': np.linspace(-90, 90, 100),
'lon': np.linspace(0, 360, 100)})
fig, ax = plot.subplots(proj='eqearth')
ax.format(coast=True)
m = ax.pcolormesh(da)
ax.colorbar(m)
Actual behavior: [What actually happened]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~/miniconda3/envs/basicf4/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)
~/miniconda3/envs/basicf4/lib/python3.8/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
250 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
251 if 'retina' in formats or 'png2x' in formats:
--> 252 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
253 if 'jpg' in formats or 'jpeg' in formats:
254 jpg_formatter.for_type(Figure, lambda fig: print_figure(fig, 'jpg', **kwargs))
~/miniconda3/envs/basicf4/lib/python3.8/site-packages/IPython/core/pylabtools.py in retina_figure(fig, **kwargs)
140 def retina_figure(fig, **kwargs):
141 """format a figure as a pixel-doubled (retina) PNG"""
--> 142 pngdata = print_figure(fig, fmt='retina', **kwargs)
143 # Make sure that retina_figure acts just like print_figure and returns
144 # None when the figure is empty.
~/miniconda3/envs/basicf4/lib/python3.8/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
132 FigureCanvasBase(fig)
133
--> 134 fig.canvas.print_figure(bytes_io, **kw)
135 data = bytes_io.getvalue()
136 if fmt == 'svg':
~/miniconda3/envs/basicf4/lib/python3.8/site-packages/proplot/figure.py in _preprocess(self, *args, **kwargs)
108 with rc_context, fig_context:
109 fig.auto_layout()
--> 110 result = func(self, *args, **kwargs)
111 return result
112
~/miniconda3/envs/basicf4/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2253 # force the figure dpi to 72), so we need to set it again here.
2254 with cbook._setattr_cm(self.figure, dpi=dpi):
-> 2255 result = print_method(
2256 filename,
2257 facecolor=facecolor,
~/miniconda3/envs/basicf4/lib/python3.8/site-packages/matplotlib/backend_bases.py in wrapper(*args, **kwargs)
1667 kwargs.pop(arg)
1668
-> 1669 return func(*args, **kwargs)
1670
1671 return wrapper
~/miniconda3/envs/basicf4/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args)
506 *metadata*, including the default 'Software' key.
507 """
--> 508 FigureCanvasAgg.draw(self)
509 mpl.image.imsave(
510 filename_or_obj, self.buffer_rgba(), format="png", origin="upper",
~/miniconda3/envs/basicf4/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in draw(self)
399 def draw(self):
400 # docstring inherited
--> 401 self.renderer = self.get_renderer(cleared=True)
402 # Acquire a lock on the shared font cache.
403 with RendererAgg.lock, \
~/miniconda3/envs/basicf4/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in get_renderer(self, cleared)
415 and getattr(self, "_lastKey", None) == key)
416 if not reuse_renderer:
--> 417 self.renderer = RendererAgg(w, h, self.figure.dpi)
418 self._lastKey = key
419 elif cleared:
~/miniconda3/envs/basicf4/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in __init__(self, width, height, dpi)
89 self.width = width
90 self.height = height
---> 91 self._renderer = _RendererAgg(int(width), int(height), dpi)
92 self._filter_renderers = []
93
ValueError: Image size of 68279018x33565395 pixels is too large. It must be less than 2^16 in each direction.
When plot.subplots(proj='cyl')
is used, there is no error but there is a large space around the figure.
Proplot version
matplotlib 3.4.2
proplot 0.7.0