holoviz / geoviews

Simple, concise geographical visualization in Python
http://geoviews.org
BSD 3-Clause "New" or "Revised" License
595 stars 77 forks source link

matplotlib ticks=False causing crashes when projected #381

Closed ahuang11 closed 4 years ago

ahuang11 commented 4 years ago
import xarray as xr
dz = xr.tutorial.open_dataset('air_temperature')['air'].isel(time=(slice(0, 2)))
dz.hvplot('lon', 'lat', coastline=True, projection=ccrs.Robinson(), xticks=False, yticks=False)

~/anaconda3/envs/py3/lib/python3.7/site-packages/cartopy/mpl/gridliner.py in _draw_gridliner(self, nx, ny, background_patch)
    306         n_steps = self.n_steps
    307 
--> 308         x_ticks = self.xlocator.tick_values(x_lim[0], x_lim[1])
    309         y_ticks = self.ylocator.tick_values(y_lim[0], y_lim[1])
    310 

~/anaconda3/envs/py3/lib/python3.7/site-packages/matplotlib/ticker.py in tick_values(self, vmin, vmax)
   2084         vmin, vmax = mtransforms.nonsingular(
   2085             vmin, vmax, expander=1e-13, tiny=1e-14)
-> 2086         locs = self._raw_ticks(vmin, vmax)
   2087 
   2088         prune = self._prune

~/anaconda3/envs/py3/lib/python3.7/site-packages/matplotlib/ticker.py in _raw_ticks(self, vmin, vmax)
   2040             steps = steps[igood]
   2041 
-> 2042         istep = np.nonzero(steps >= raw_step)[0][0]
   2043 
   2044         # Classic round_numbers mode may require a larger step.

IndexError: index 0 is out of bounds for axis 0 with size 0

Then with my data:

~/anaconda3/envs/py3/lib/python3.7/site-packages/cartopy/mpl/gridliner.py in _draw_gridliner(self, nx, ny, background_patch)
    306         n_steps = self.n_steps
    307 
--> 308         x_ticks = self.xlocator.tick_values(x_lim[0], x_lim[1])
    309         y_ticks = self.ylocator.tick_values(y_lim[0], y_lim[1])
    310 

~/anaconda3/envs/py3/lib/python3.7/site-packages/matplotlib/ticker.py in tick_values(self, vmin, vmax)
   2084         vmin, vmax = mtransforms.nonsingular(
   2085             vmin, vmax, expander=1e-13, tiny=1e-14)
-> 2086         locs = self._raw_ticks(vmin, vmax)
   2087 
   2088         prune = self._prune

~/anaconda3/envs/py3/lib/python3.7/site-packages/matplotlib/ticker.py in _raw_ticks(self, vmin, vmax)
   2030             nbins = self._nbins
   2031 
-> 2032         scale, offset = scale_range(vmin, vmax, nbins)
   2033         _vmin = vmin - offset
   2034         _vmax = vmax - offset

~/anaconda3/envs/py3/lib/python3.7/site-packages/matplotlib/ticker.py in scale_range(vmin, vmax, n, threshold)
   1833     else:
   1834         offset = math.copysign(10 ** (math.log10(abs(meanv)) // 1), meanv)
-> 1835     scale = 10 ** (math.log10(dv / n) // 1)
   1836     return scale, offset
   1837 

ZeroDivisionError: float division by zero
jbednar commented 4 years ago

I'm a bit confused here because your example is using hvplot, which does not support Matplotlib. hvPlot has code for translating the xticks option into Bokeh's option format, but it doesn't have any support for translating such arguments into Matplotlib's options. To use Matplotlib with this code would require extensions to hvPlot, not GeoViews, so I'll close this. Feel free to reopen this issue if you can provide a reproducible example using Matplotlib + GeoViews (without hvplot).