在 Plotly 中,是否可以更改图例框的大小?

5

example of legend box in plotly

在我的代码中,当我用一个更小的值改变字体大小时,图例框不会适应新的大小。你知道我可以添加什么属性来调整框的大小吗?
所使用的库是Plotly。
fig.update_layout(showlegend=True, height=500, width=1000, title_text="Analysis of Latency",
                  legend=dict(
                      x=0, y=1,traceorder="normal",font=dict(size=10),bgcolor="WhiteSmoke")

enter image description here


2
修改Plotly图表中的图例大小。我发现这个答案非常有帮助。 - r-beginners
4
你提到的答案遵循了我已经拥有的相同代码:legend=dict(font=dict(size=10))(在R中不是字典,而是列表)。然而,这种方法只能改变图例框内的字体大小。但是图例框本身的尺寸并没有改变。 - jessirocha
1个回答

0

在看到一些评论建议这不能完成的各种问题后,似乎有一种相当不错的方法。

legend.sizes = seq(80, 160, 20)
ax = list(zeroline = FALSE, showline = FALSE, showticklabels = FALSE, showgrid = FALSE)
mk = list(sizeref=0.1, sizemode="area")

p.map = plot_geo(DF, locationmode = 'USA-states') %>%
  add_markers(x = ~long, y = ~lat, color = ~Group, size = ~Value, marker = mk) %>%
  layout(geo = list(scope = 'usa'))

p.legend = plot_ly() %>%
  add_markers(x = 1, y = legend.sizes, size = legend.sizes, showlegend = F, marker = mk) %>%
  layout(xaxis = ax, yaxis = list(showgrid = FALSE))

subplot(p.legend, p.map, widths = c(0.1, 0.9))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接