【问题标题】:Is it possible to change the size of the legend box in Plotly?是否可以在 Plotly 中更改图例框的大小?
【发布时间】:2020-11-02 03:32:34
【问题描述】:

在我的代码中,当我用较小的值更改字体大小时,图例框不适应新的大小。你知道我可以添加什么属性来调整盒子的大小吗?

使用的库是 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")

【问题讨论】:

  • Change legend size in plotly chart 我觉得这个答案很有帮助
  • 您提到的答案遵循我已经拥有的相同代码:legend=dict(font=dict(size=10))(而不是字典,在 R 中它是一个列表)。但是,这种方法只会更改图例框内的字体大小。但是图例框本身的尺寸没有改变。

标签: python plotly data-visualization


【解决方案1】:

在看到一些关于各种问题的 cmet 表明这无法完成后,似乎有一种方法非常有效。

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))

【讨论】:

    猜你喜欢
    • 2022-09-23
    • 1970-01-01
    • 2018-04-17
    • 2016-06-09
    • 1970-01-01
    • 2015-10-20
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    相关资源
    最近更新 更多