jar*_*jar 2 python charts python-3.x altair
我知道axis=None用于隐藏轴线。但是,当您主动使用axis修改图形时,是否可以只保留刻度,而隐藏 X 轴和 Y 轴的轴线?
例如,这是我希望它发生的图表 -
import pandas as pd
import altair as alt
df = pd.DataFrame({'a': [1,2,3,4], 'b':[2000,4000,6000,8000]})
alt.Chart(df).mark_trail().encode(
x=alt.X('a:Q', axis=alt.Axis(titleFontSize=12, title='Time ?', labelColor='#999999', titleColor='#999999', titleAlign='right', titleAnchor='end', titleY=-30)),
y=alt.Y('b:Q', axis=alt.Axis(format="$s", tickCount=3, titleFontSize=12, title='Cost ?', labelColor='#999999', titleColor='#999999', titleAnchor='end')),
size=alt.Size('b:Q', legend=None)
).configure_view(strokeWidth=0).configure_axis(grid=False)
Run Code Online (Sandbox Code Playgroud)
输出应该看起来像这个 SO post 中的刻度线。
注意:该帖子中的情节与此处提供的演示无关。它只是为了理解目的。
Vega-Lite 将轴线称为domain。您可以通过传递domain=False给轴配置来隐藏它:
import pandas as pd
import altair as alt
df = pd.DataFrame({'a': [1,2,3,4], 'b':[2000,4000,6000,8000]})
alt.Chart(df).mark_trail().encode(
x=alt.X('a:Q', axis=alt.Axis(titleFontSize=12, title='Time ?', labelColor='#999999', titleColor='#999999', titleAlign='right', titleAnchor='end', titleY=-30)),
y=alt.Y('b:Q', axis=alt.Axis(format="$s", tickCount=3, titleFontSize=12, title='Cost ?', labelColor='#999999', titleColor='#999999', titleAnchor='end')),
size=alt.Size('b:Q', legend=None)
).configure_view(strokeWidth=0).configure_axis(grid=False, domain=False)
Run Code Online (Sandbox Code Playgroud)