python - 更改 Altair 图中的图例编号范围

标签 python plot scale legend altair

我正在尝试使用 Altair 包以“气候条纹图”的形式绘制时间序列数据。 问题是我不知道如何更改图例中的范围以标准化具有相同颜色范围和图例中数字的所有图。目前,每次我绘制一些内容时,图例都会适应数据的范围。

我认为问题出在“domain”属性上,也许不在正确的位置?

感谢您的帮助:)

这是绘图的代码:

chart=alt.Chart(source).mark_rect().encode(
    x=('day:O'),
    y='subasins:N',
    color=alt.Color('90%:Q',legend=alt.Legend(title='CH4'), bin=alt.Bin(maxbins=20),
                    scale=alt.Scale(scheme='blueorange'),domain=[1830,2000]) 
    
).properties(width=100).facet(column=alt.Column('month'))

chart.show()

Plots that I get now with different scales in the legend

最佳答案

您对 domain 使用了正确的方法,只需将其放入 alt.Scale 中即可:

scale=alt.Scale(scheme='blueorange', domain=[1830, 2000])

关于python - 更改 Altair 图中的图例编号范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66158128/

相关文章:

MATLAB 子图标题和轴标签

delphi - 对 TMonthCalendar 使用 ScaleBy 方法

python - 使用 TensorFlow 的梯度下降比基本的 Python 实现慢得多,为什么?

Python 和 MySQL 不正确的字符串值

r - 使用 R 更改时间序列图中的 X 轴值

python - 如何将数据帧每一行的观察结果绘制为线图

iphone - 使用 UIImagePickerController 拍照后如何调整图片大小?

r - 使用 ggplot2 绘图 : "Error: Discrete value supplied to continuous scale" on categorical y-axis

python - 添加 datetime.datetime 和 datetime.time

python - 尝试通过 _winreg 获取 MachineGuid 但无法正常工作