gpt4 book ai didi

python - 使用 holoviews/hvplot 更改图例位置

转载 作者:行者123 更新时间:2023-12-01 00:35:33 25 4
gpt4 key购买 nike

Hvplot 默认图例位置位于图的右侧。
如何更改此默认图例位置?

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

最佳答案

您可以通过在代码中添加 .opts(legend_position='top_left') 将图例位置更改为左上角。

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

如果您想将图例放置在绘图内部,您可以从以下选项中进行选择:

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

如果您想将图例放置在绘图外部,您可以从以下选项中进行选择:

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

enter image description here

关于python - 使用 holoviews/hvplot 更改图例位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57808328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com