将分散颜色方案设置为以Altai中的零为中心

2024-07-03 06:25:08 发布

您现在位置:Python中文网/ 问答频道 /正文

对于发散的色阶,如何使色阶以零为中心呢。在


Tags: 中心色阶使色
1条回答
网友
1楼 · 发布于 2024-07-03 06:25:08

一种方法是显式地将域设置为对称:

import numpy as np
import pandas as pd
import altair as alt

df = pd.DataFrame(np.random.randn(100, 3), columns=['x', 'y', 'z'])
alt.Chart(df).mark_point().encode(
  x='x',
  y='y',
  color=alt.Color('z', scale=alt.Scale(scheme='blueorange', domain=[-3, 3]))
)

enter image description here

相关问题 更多 >