散布的编辑大小

发布于 2025-02-09 12:23:32 字数 456 浏览 3 评论 0原文

这是我简单的情节图表的示例:

px.scatter(data_frame=testdf,
       x = 'some_x',
       y = 'some_y',
       size = 'some_size',
       color = 'sth_colorful',
       title = 'stackoverflow',
       range_x = [-10, 1100],
       range_y = [-0.08, 1],
       hover_name = 'sth_i_want_to_check',
       animation_frame = 'year_of_course'
      )

这是非常好的。令我困扰的一件事是,“ some_size”最小值约为20,最大值约为35,因此很难注意到圆圈之间的大小差异。 有什么方法可以管理这些直径?我想保留原始值以悬停。

Here's a sample of my simple plotly chart:

px.scatter(data_frame=testdf,
       x = 'some_x',
       y = 'some_y',
       size = 'some_size',
       color = 'sth_colorful',
       title = 'stackoverflow',
       range_x = [-10, 1100],
       range_y = [-0.08, 1],
       hover_name = 'sth_i_want_to_check',
       animation_frame = 'year_of_course'
      )

It is alomost good. One thing that bothers me is that 'some_size' min value is about 20 and max is about 35 so it is hard to notice the size difference between the circles.
Is there a way I can manage the diameter of these? I'd like to keep the original values to appear in a hover.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后来的我们 2025-02-16 12:23:32

当您将参数size ='Some_size'传递给px.scatter时,这直接确定标记在图上呈现时的大小。

但是,您可以采取的措施是创建一个新列,称为“ display_ize”,带有标记的预期尺寸,并将custydata设置为df [ 'some_size'],因此您可以在HoverTemplate中访问这些值。

之后,您可以循环浏览px.scatter中的所有跟踪,并修改HoverTemplate以显示Some_Size而不是display_size。

例如:

## increase the standard deviation of the size values
## so that the difference between small and large markers is more apparent
testdf["display_size"] = 2*test_df["some_size"]

fig = px.scatter(data_frame=testdf,
       x = 'some_x',
       y = 'some_y',
       size = 'display_size',
       color = 'sth_colorful',
       title = 'stackoverflow',
       range_x = [-10, 1100],
       range_y = [-0.08, 1],
       hover_name = 'sth_i_want_to_check',
       animation_frame = 'year_of_course'
      )

fig.update_traces(customdata=testdf["some_size"])

## replace marker.size in the hovertemplate with your customdata (the actual size values)
for trace in fig.data:
    trace['hovertemplate'] = trace['hovertemplate'].replace('marker.size','customdata')

When you pass the argument size = 'some_size' to px.scatter, this directly determines the size of the markers as they render on the plot.

However, what you can do to get around this is create a new column called "display_size" with your intended sizes for the markers, and set customdata to df['some_size'] so you can access these values in the hovertemplate.

After that, you can loop through all of the traces in your px.scatter and modify the hovertemplate to display some_size instead of display_size.

For example:

## increase the standard deviation of the size values
## so that the difference between small and large markers is more apparent
testdf["display_size"] = 2*test_df["some_size"]

fig = px.scatter(data_frame=testdf,
       x = 'some_x',
       y = 'some_y',
       size = 'display_size',
       color = 'sth_colorful',
       title = 'stackoverflow',
       range_x = [-10, 1100],
       range_y = [-0.08, 1],
       hover_name = 'sth_i_want_to_check',
       animation_frame = 'year_of_course'
      )

fig.update_traces(customdata=testdf["some_size"])

## replace marker.size in the hovertemplate with your customdata (the actual size values)
for trace in fig.data:
    trace['hovertemplate'] = trace['hovertemplate'].replace('marker.size','customdata')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文