Ram Rachum
Ram Rachum

Reputation: 88708

Altair chart: Show less lines in the grid

I'm working on a chart using Altair, and I'm trying to figure out how to have less lines in the background grid. Is there a term for that background grid?

Here's a chart that looks like mine, that I took from the tutorial:

Let's say that I want to have half as many grid lines on the X axis. How could I do that?

Upvotes: 5

Views: 2615

Answers (1)

jakevdp
jakevdp

Reputation: 86463

Grid lines are drawn at the location of ticks, so to adjust the grid lines you can adjust the ticks. For example:

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)'
)

enter image description here

You can see other tick-related properties in the documentation for alt.Axis.

Upvotes: 3

Related Questions