Search code examples
pythonholoviewshvplotholoviz

Change legend position using holoviews / hvplot


Hvplot has default the position of the legend on the right outside of the plot.
How can I change this default legend position?

import numpy as np
import pandas as pd
import hvplot
import hvplot.pandas
import holoviews as hv

data = np.random.normal(size=[50, 2])
df = pd.DataFrame(data, columns=['a', 'b'])
df.hvplot.line()

enter image description here


Solution

  • You can change the legend position to top left by adding .opts(legend_position='top_left') to your code.

    df.hvplot.line().opts(legend_position='top_left')
    

    If you would like to position your legend inside your plot, you can choose from the following options:

    ['top_right', 'top_left', 'bottom_left', 'bottom_right']

    If you want to place your legend outside your plot, you can choose from these options:

    ['right', 'left', 'top', 'bottom']

    enter image description here