【问题标题】:Altair Scatter Plot tickMinStepAltair 散点图 tickMinStep
【发布时间】:2022-01-15 21:49:17
【问题描述】:

我有这个数据框:

    x           y           term        s
0   0.000000    0.132653    matlab      0.893072
1   0.000000    0.142857    matrix      0.905120
2   0.012346    0.153061    laboratory  0.902610
3   0.987654    0.989796    be          0.857932
4   0.938272    0.959184    a           0.861948

并生成了这张图表:

使用此代码:

chart = alt.Chart(scatterdata_df).mark_circle().encode(
        x = alt.X('x:Q', axis = alt.Axis(title = "⏪  less physical | more physical ⏩", tickMinStep = 0.05)),
        y = alt.Y('y:Q', axis = alt.Axis(title = "⏪  less data | more data ⏩", tickMinStep = 0.05)),
        color = alt.Color('s:Q', scale=alt.Scale(scheme='redblue')),
        tooltip = ['term']
    ).properties(
        width = 500,
        height = 500
    )

已经为 x 和 y 轴设置了tickMinStep = 0.05,我不确定为什么图表没有反映这个参数。

谢谢。

【问题讨论】:

    标签: python scatter-plot altair vega-lite


    【解决方案1】:

    tickMinStep 指定自动确定刻度的最小刻度间距;实际刻度间距可能大于此。听起来您想要比默认启发式提供更多的刻度,因此您应该直接调整 tickCount

    import altair as alt
    import pandas as pd
    import numpy as np
    
    rng = np.random.default_rng(0)
    
    data = pd.DataFrame({
        'x': rng.random(size=100),
        'y': rng.random(size=100)
    })
    
    alt.Chart(data).mark_point().encode(
        x=alt.X('x:Q', axis=alt.Axis(tickCount=20)),
        y=alt.Y('y:Q', axis=alt.Axis(tickCount=20)),
    )
    

    如果您想更好地控制刻度值,您可以将值列表直接传递给Axis.values。有关详细信息,请参阅 alt.Axis 文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-19
      • 2022-01-14
      • 2022-11-14
      • 2023-03-15
      • 2021-01-19
      • 2020-09-07
      • 2020-05-03
      • 1970-01-01
      相关资源
      最近更新 更多