简体   繁体   English

图例中的 Plotly 散点图(气泡图)标记大小

[英]Plotly scatter (bubble plot) marker size in legend

Is there a way to show marker size (bubble size) within the legend of a graph in plotly express (plotly python).有没有办法在 plotly express (plotly python)的图例中显示标记大小(气泡大小)。 For example using the code below, it shows the population using the marker size.例如,使用下面的代码,它使用标记大小显示总体。

df = px.data.gapminder().query("year==2007")
fig = px.scatter(df, x="gdpPercap", y="lifeExp", color="continent",
    size="pop", size_max=45, log_x=True)
fig.show()

Output: Output: 在此处输入图像描述

Matplotlib has something similar using the .legend_elements("sizes") (see here, creating a matplotlib scatter legend size related ), was wondering if there is something in Plotly as well. Matplotlib 使用.legend_elements("sizes")有类似的东西(参见此处, 创建 matplotlib 散点图例大小相关),想知道 ZA5E13387C005FE8D4E1C67F40A8 中是否有一些东西。

If you have multiple scatter plots, the size of the legend is basically linked to the size of each marker.如果您有多个散点图,则图例的大小基本上与每个标记的大小相关。 As a means of aligning them, you can use the raft setting.作为对齐它们的一种方式,您可以使用 raft 设置。 API here Offical Reference API 这里官方参考

fig.update_layout(legend= {'itemsizing': 'trace'})
# Constant: same, Trace: individual marker size

The marker size of your question is a categorical variable, so there is no effect of changing the size.您问题的标记大小是一个分类变量,因此更改大小没有影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM