Search code examples
pythonaltair

Removing space between marks in altair visualization


I have a visualization where I am trying to increase mark size and also have them touching (decrease the space in-between the marks) using altair. Is there a way to do this without simply using 'size='? I would like to make this adaptable to a function and not hardcode the size, but have it dependable on the data given.

Here is my current code so far:

alt.Chart(df).mark_square().encode(
x=alt.X('p1:N'),
y=alt.Y('p2:N'),
color=alt.Color('weight:O', legend=alt.Legend(type='symbol'), scale=alt.Scale(scheme='blues'))
               
).properties(
    height=500,
    width=500
 )

My current output:

enter image description here

My intended output I am trying to achieve:

enter image description here


Solution

  • If you use mark_rect() rather than mark_square() with a nominal or ordinal encoding, the size of each mark will automatically be adjusted to fill the space.