简体   繁体   中英

How to hide axis lines but show ticks in a chart in Altair, while actively using “axis” parameter?

I am aware of using axis=None to hide axis lines. But when you have actively used axis to modify the graph, is it possible to keep just the ticks, but hide the axis lines for both X and Y axis?

For example, here is a graph I have where I'd like it to happen -

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)

The output should look like the ticks in this SO post .
Note: The plot in that post has nothing to do with the demo provided here. its just for understanding purposes.

Vega-Lite calls the axis line the domain . You can hide it by passing domain=False to the axis configuration:

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)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM