python - Plotly 中的一个图有两个或三个颜色条

标签 python plotly plotly-dash colorbar

我有一个 Scattergl 图,我希望它有两个或三个颜色条。每个颜色条都有与不同数据特征相关的不同色标。图中的点被着色为两种或三种色标颜色的组合。我已经有了颜色部分的组合,但我不知道如何绘制颜色条……而且我不确定是否允许绘制多个颜色条。您知道如何执行此操作吗?

非常感谢您的帮助!提前致谢。 亲切的问候。

最佳答案

很高兴看到更多 sansanos 使用 plotly,标记的颜色栏内有一个属性用于此目的,trace.marker.colorbar.x,它需要一个范围从 -2 到 3 的值,与0 是图的左极限,1 是右极限,您通常必须通过反复试验来获得它。

请记住,提供您的代码示例总是有用的,因此我们可以根据您正在使用的范例提供更正。这是一个例子

from plotly import graph_objects as go

data_x = [1, 2, 3, 4, 5, 6]
data_y = [1, 4, 9, 16, 25, 36]

figure = go.FigureWidget()

# First
first_scatter = go.Scattergl()

first_scatter.mode = 'markers'
first_scatter.x = data_x
first_scatter.y = data_y

first_scatter.marker.colorscale = 'Viridis'
first_scatter.marker.color = data_y
first_scatter.marker.size = 20
first_scatter.marker.showscale = True

first_scatter.showlegend = False
figure.add_trace(first_scatter)

# Second
second_scatter = go.Scattergl()

second_scatter.mode = 'markers'
second_scatter.x = data_x
second_scatter.y = data_y[::-1]

second_scatter.marker.colorscale = 'Electric'
second_scatter.marker.color = data_y
second_scatter.marker.size = 20
second_scatter.marker.showscale = True
second_scatter.marker.colorbar.x = 1.15 # Here

second_scatter.showlegend = False
figure.add_trace(second_scatter)

example

关于python - Plotly 中的一个图有两个或三个颜色条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60458220/

相关文章:

python - 在Eve中,如何安全地存储用户的密码?

python - 使用整数转换进行舍入是否有不良副作用?

javascript - Plotly.js 在悬停在图表标题上时显示工具提示

r - 在水平绘图子图图中共享 x 轴标签

python - 在 dash 中,选择单选按钮时如何使用回调来更新图表?

python - 全局变量更新者和间隔组件

python - 向现有对象实例添加方法

Python 偏写读写锁

python - 在绘图中应用条件不透明度

python - 在 Dash 中构建仪表板