jar
jar

Reputation: 2908

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.

Upvotes: 10

Views: 6312

Answers (1)

jakevdp
jakevdp

Reputation: 86330

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)

enter image description here

Upvotes: 11

Related Questions