Ben Chuanlong Du's Blog

It is never too late to learn.

Axis Range of Plots in HoloViews

In [2]:
import pandas as pd
import holoviews as hv

hv.extension("bokeh")
In [3]:
daily = pd.read_csv("../../home/media/data/daily.csv")
daily.head()
Out[3]:
date x y z
0 2019-01-11 0.00 0.000000 0.00
1 2019-01-10 30436.96 0.000000 0.00
2 2019-01-09 30132.28 212952.094433 128.52
3 2019-01-08 29883.24 352014.450160 192.18
4 2019-01-07 29843.17 375139.756514 172.62

Setting the Dimension Ranges Explicitly¶

In [26]:
%%opts Scatter [width=600 height=500 scaling_method='width' scaling_factor=2 size_index=2 show_grid=True] 

xdim = hv.Dimension('x', range=(0, 45000))
ydim = hv.Dimension('y', range=(0, 800000))
hv.Scatter((daily.x, daily.y), xdim, ydim)
Out[26]:

Using redim.range

Notice that the keyword names in redim.range must match the specified dimension names.

In [29]:
%%opts Scatter [width=600 height=500 scaling_method='width' scaling_factor=2 size_index=2 show_grid=True] 

hv.Scatter((daily.x, daily.y), 'x', 'y').redim.range(x=(0, 45000), y=(0, 800000))
Out[29]:

Use options

options is the easiest way to change axis ranges. When there are multiple subplots, you have to either set different dimension names or use the option axiswise=True.

In [32]:
%%opts Scatter [width=600 height=500 scaling_method='width' scaling_factor=2 size_index=2 show_grid=True] 

hv.Scatter((daily.x, daily.y)).options(xlim=(0, 45000), ylim=(0, 800000))
Out[32]:
In [5]:
%%opts Scatter [width=400 height=400 scaling_method='width' scaling_factor=2 size_index=2 show_grid=True] 

hv.Scatter((daily.x, daily.z), 'x', 'z') + \
hv.Scatter((daily.x, daily.y)).options(xlim=(0, 45000), ylim=(0, 800000))
Out[5]:

Use axiswise=True for it to work when the dimensions of subplots are identical.

In [6]:
%%opts Scatter [width=400 height=400 scaling_method='width' scaling_factor=2 size_index=2 show_grid=True] 

hv.Scatter((daily.x, daily.z), 'x', 'y') + \
hv.Scatter((daily.x, daily.y), 'x', 'y').options(xlim=(0, 45000), ylim=(0, 800000), axiswise=True)
Out[6]:
In [7]:
%%opts Scatter [width=400 height=400 scaling_method='width' scaling_factor=2 size_index=2 show_grid=True] 

hv.Scatter((daily.x, daily.z)).options(axiswise=True) + \
hv.Scatter((daily.x, daily.y)).options(axiswise=True)
Out[7]:
In [39]:
%%opts Layout [shared_axes=False]

hv.Scatter((daily.x, daily.z)).options(axiswise=True) + hv.Scatter((daily.x, daily.y)).options(axiswise=True)
Out[39]:
In [ ]:
 

Comments