【问题标题】:Remove border around vegaEmbed geoshape generated by altair?删除由 altair 生成的 vegaEmbed geoshape 周围的边框?
【发布时间】:2019-06-17 20:30:26
【问题描述】:

在下图中,观察从Chart.save() 生成到 HTML 或 JSON 画布的地图周围的边框(边框在画布内部,不是 CSS 样式的)。

对于任何其他类型的标记,人们希望能够使用Chart.configure_view() 设置strokeWidth=0 来移除边框,但这似乎不会影响此geoshape 图表。

vegaEmbed embed options 似乎没有记录创建此边框的原因。

是否可以设置样式或移除边框?

【问题讨论】:

    标签: python vega vega-lite altair


    【解决方案1】:

    去除边框的方法是使用configure_view(strokeWidth=0)

    这是一个示例,使用最新版本的 Altair 和最新版本的 Vega-Lite:

    import altair as alt
    from vega_datasets import data
    
    counties = alt.topo_feature(data.us_10m.url, 'counties')
    source = data.unemployment.url
    
    alt.Chart(counties).mark_geoshape().encode(
        color='rate:Q'
    ).transform_lookup(
        lookup='id',
        from_=alt.LookupData(source, 'id', ['rate'])
    ).project(
        type='albersUsa'
    ).configure_view(
        strokeWidth=0
    )
    

    如果您看到不同的结果,则可能是您的前端渲染器已过时,您应确保使用最新版本的 Vega-Lite 来渲染图表。

    【讨论】:

    • 谢谢,你说得对;更新所有内容并使用 configure_view(strokeWidth=0) 确实删除了边框。我不确定正确的程序,但我会将我的问题留给可能遇到自己的用户错误的其他人(尽管也许应该编辑问题?)
    猜你喜欢
    • 1970-01-01
    • 2011-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    • 2011-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多