I am plotting points on top of geographical tiles, and the initial plot has an appropriate aspect ratio for the geographical tiles regardless of the xlim and ylim as well as the extents of the points plotted on top. However, when updating the points plotted on top, say by changing to a different dataset, the aspect ratio is off depending on the exact xlim and ylim.
In addition, when zooming in or out on the map, the aspect ratio is reset to the proper aspect, but updating the dataset readjusts the plot despite having apply_ranges=False. This further screws up the aspect ratio in different ways which appear random. If one of the plots has a colorbar, the effect is even worse.
MWE:
import numpy as np
import pandas as pd
import holoviews as hv
import hvplot.pandas
hv.extension('bokeh', logo=False)
import panel as pn
import param
data_1 = pd.DataFrame(np.random.normal(0, 1000000, size=(10,2))).rename(columns={0: 'easting', 1: 'northing'})
data_2 = pd.DataFrame(np.random.normal(0, 1000000, size=(10,2))).rename(columns={0: 'easting', 1: 'northing'})
tiles = hv.element.tiles.StamenTerrainRetina()
tiles.opts(height=800, width=800, xlim=(-2000000, 2000000), ylim=(-1500000, 1500000))
class DataParameters(param.Parameterized):
dataset = param.Selector(objects=['Data 1', 'Data 2'])
data_params = DataParameters()
@pn.depends(dataset=data_params.param.dataset)
def plot_data(dataset):
if dataset == 'Data 1':
plot = data_1.hvplot(kind='points', x='easting', y='northing', color='red')
else:
plot = data_2.hvplot(kind='points', x='easting', y='northing', color='red')
plot.opts(apply_ranges=False)
return plot
dataview = hv.DynamicMap(plot_data)
panel_row = pn.Row(data_params, tiles*dataview)
bokeh_server = panel_row.show(port=12345)
#%%
# stop the bokeh server (when needed)
bokeh_server.stop()