0
votes

I'm currently trying to use holoviews+datashader with the matplotlib backend. The data I'm using has very different x and y ranges and the result is that the datashader plots are stretched unhelpfully. The opts and output keywords I've tried using can solve the problem with the holoviews only plots but not once datashade is applied.

For example:

import holoviews as hv
hv.extension('matplotlib')
import numpy as np
from holoviews.operation.datashader import datashade

np.random.seed(1)
positions = np.random.multivariate_normal((0,0),[[0.1,0.1], [0.1,50.0]], (1000000,))
positions2 = np.random.multivariate_normal((0,0),[[0.1,0.1], [0.1,50]], (1000,))
points = hv.Points(positions,label="Points")
points2 = hv.Points(positions2,label="Points2")
plot = datashade(points) + points2
plot

Generates: datashader and points output

I can control the size of the points only plot using the fig_size opts keyword

e.g. points2(plot=dict(fig_size=200))

but the same doesn't work for datashader plots. Any advice for changing the size of such datashader figures with matplotlib would be greatly appreciated. Ideally, I'd like to use functions and not cell magic keywords so the code can be ported to a script.

Thanks!

1

1 Answers

0
votes

Changing the size of matplotlib plots in HoloViews is always controlled by the outer container, so when you have a Layout you can change the size on that object, e.g. in your example that would be:

plot = datashade(points) + points2
plot.opts(plot=dict(fig_size=200))

The other part that might be confusing is that RGB elements (which is what datashade operation returns) uses aspect='equal' by default. You can change that by setting aspect to 'square' or an explicit aspect ratio:

datashade(points).opts(plot=dict(fig_size=200, aspect='square'))

Putting that together you might want to do something like this:

plot = datashade(points).opts(plot=dict(aspect='square')) + points2
plot.opts(plot=dict(fig_size=200))