【问题标题】:Altair chart: Show less lines in the gridAltair 图表:在网格中显示较少的线条
【发布时间】:2021-09-21 17:09:38
【问题描述】:

我正在使用 Altair 制作图表,并试图弄清楚如何在背景网格中减少线条。这个背景网格有术语吗?

这是一张看起来像我的图表,我从the tutorial 获取的:

假设我想在 X 轴上有一半的网格线。我怎么能这样做?

【问题讨论】:

    标签: python charts altair vega-lite vega


    【解决方案1】:

    网格线是在刻度的位置绘制的,因此要调整网格线,您可以调整刻度。例如:

    import altair as alt
    import numpy as np
    import pandas as pd
    
    x = np.arange(100)
    source = pd.DataFrame({
      'x': x,
      'f(x)': np.sin(x / 5)
    })
    
    alt.Chart(source).mark_line().encode(
        x=alt.X('x', axis=alt.Axis(tickCount=4)),
        y='f(x)'
    )
    

    您可以在alt.Axis 的文档中查看其他与刻度相关的属性。

    【讨论】:

    • 感谢您的快速答复。我想以 x 为单位指定刻度数,而不是 X 轴范围内的总数。这可能吗?
    • 您应该可以通过tickMinStep 执行此操作,但不幸的是,Altair 所针对的 Vega-Lite 版本中有一个 bug,这使得网格线不尊重这一点。
    • 我明白了,谢谢
    猜你喜欢
    • 1970-01-01
    • 2014-04-14
    • 1970-01-01
    • 1970-01-01
    • 2021-09-27
    • 2020-12-08
    • 1970-01-01
    • 1970-01-01
    • 2018-03-17
    相关资源
    最近更新 更多