Home > Blockchain >  Issue with altair facet label
Issue with altair facet label

Time:10-07

I want the row label of a facetted altair line chart to appear on the right side. Here, is the code with a toy data generator and the output

import itertools
import random

def gen_toy_data():
    groups = ["A", "B", "C"]
    axes = ['x','y','z']
    comb = list(itertools.product(groups,axes))
    df_ar = []
    for grp, ax in comb:
        df_temp = pd.DataFrame()
        df_temp['Timestamp'] = pd.date_range("2022-01-01", periods=30, freq="H")
        df_temp['grp'] = grp
        df_temp['axis'] = ax
        df_temp['value'] = random.sample(range(1, 50), 30)
        df_ar.append(df_temp)
    df = pd.concat(df_ar)
    return df

df = gen_toy_data()

alt.Chart(df).mark_line(size=1).encode(
    x=alt.X('Timestamp:T',axis=alt.Axis(format="%H:%M")),
    y=alt.Y('value:Q',axis=alt.Axis( grid = False)),
    color=alt.Color('axis:N', title='Axes'), 
    tooltip=['Timestamp', 'axis', 'grp', 'value'],
    row =alt.Row('grp:O',title = 'Group', 
            header=alt.Header(
                #orient='right'
                 labelOrient='right',
                 #labelAlign='right',
                 titleOrient='right',
                 #titleAlign='right'
        )
    )
).properties(width=width, height=50)

enter image description here

titleOrient works but labelOrient puts the label on the right side of the Y-axis. I want to place it where Group is.

The same setting produced the desired result when I used it on a mark_bar plot, but is acting weird with mark_line.

Also, is there anyway I can avoid the repeating value label on the left side and put it only once.

CodePudding user response:

I think this was a bug in the latest version of Altair. Running the development version (installed from GitHub), I get this outupt from your code:

enter image description here

  • Related