如何在Plotly Express中更新range_color?

发布于 2025-02-08 21:35:33 字数 531 浏览 2 评论 0原文

我使用的是Plotly Express,我想显示一些数据:

import plotly.express as px
dfx = px.data.tips()
fig = px.scatter(dfx, 
                 x='total_bill', y='tip', 
                 color='size', 
                 template='plotly_dark', 
                 range_color=[2,4])

我的目标是在定义范围后更新范围颜色。

我尝试了这样的事情:

fig.update_layout(range_color=[3,6])

ValueError: Invalid property specified for object of type plotly.graph_objs.Layout: 'range'

但是没有成功。

您是否知道我需要编写的内容才能更新范围颜色值?

I am using plotly express and I want to display some data:

import plotly.express as px
dfx = px.data.tips()
fig = px.scatter(dfx, 
                 x='total_bill', y='tip', 
                 color='size', 
                 template='plotly_dark', 
                 range_color=[2,4])

My goal is to update the range color after it has been defined.

I tried something like this:

fig.update_layout(range_color=[3,6])

ValueError: Invalid property specified for object of type plotly.graph_objs.Layout: 'range'

but without success.

Are you aware of what I need to write in order to update the range color values?

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

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

发布评论

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

评论(2

机场等船 2025-02-15 21:35:33

为了更改颜色条的范围,您将更改颜色轴的最大值和最小值。这与图形设置的描述不同,可以在fig.layout中找到。

import plotly.express as px
dfx = px.data.tips()
fig = px.scatter(dfx, 
                 x='total_bill', y='tip', 
                 color='size', 
                 template='plotly_dark', 
                 range_color=[2,4])

fig.update_layout(coloraxis=dict(cmax=6, cmin=3))

fig.show()

To change the range of the color bar, you would change the maximum and minimum values of the color axis. This is different from the description of the graph settings, which can be found in fig.layout.

import plotly.express as px
dfx = px.data.tips()
fig = px.scatter(dfx, 
                 x='total_bill', y='tip', 
                 color='size', 
                 template='plotly_dark', 
                 range_color=[2,4])

fig.update_layout(coloraxis=dict(cmax=6, cmin=3))

fig.show()

enter image description here

撧情箌佬 2025-02-15 21:35:33

我认为您需要在px中使用range_color。扫描函数

import plotly.express as px
df = px.data.iris()
fig = px.scatter(df,
   x="sepal_width",
   y="sepal_length",
   color="sepal_length",
   color_continuous_scale=["red",
   "green", "blue"])
fig.show()

这是指向文档的链接 plotly

您也可以

此处查看图。

在 的文档

fig.update_layout(colorscale = dict(...))

update_layout Layout-ColorScale“ rel =“ nofollow noreferrer”>更新ColorsCale

I think you need to use range_color in the px.scatter function

import plotly.express as px
df = px.data.iris()
fig = px.scatter(df,
   x="sepal_width",
   y="sepal_length",
   color="sepal_length",
   color_continuous_scale=["red",
   "green", "blue"])
fig.show()

Here is a link to the documentation plotly

You can also look here at fig.update_coloraxes

update coloraxes

Also just found this in the documentation for update_layout

fig.update_layout(colorscale=dict(...))

update colorscale

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文