【问题标题】:Is it possible to add black grid lines to python Altair Heatmap plots?是否可以在 python Altair Heatmap 图中添加黑色网格线?
【发布时间】:2020-04-10 14:45:37
【问题描述】:

是否可以将黑色网格线添加到 Altair 热图中?

我知道可以使用scale.bandPaddingInner 在单元格之间添加间距,我想也许可以用黑色为该间距着色?

我想要的是这样的:Heatmap with Black Grid lines

【问题讨论】:

    标签: python heatmap altair gridlines


    【解决方案1】:

    是的,您可以使用rect 标记的stroke 属性执行此操作。改编 Altair 文档中的 heatmap example

    import altair as alt
    import numpy as np
    import pandas as pd
    
    # Compute x^2 + y^2 across a 2D grid
    x, y = np.meshgrid(range(-5, 5), range(-5, 5))
    z = x ** 2 + y ** 2
    
    # Convert this grid to columnar data expected by Altair
    source = pd.DataFrame({'x': x.ravel(),
                         'y': y.ravel(),
                         'z': z.ravel()})
    
    alt.Chart(source).mark_rect(stroke='black', strokeWidth=2).encode(
        x='x:O',
        y='y:O',
        color='z:Q'
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-09
      • 1970-01-01
      • 2014-07-03
      • 1970-01-01
      相关资源
      最近更新 更多