Smartly place labels in Altair

Viewed 124

I have a complex graph made in Altair including labels. Now, the problem is that the labels on the right side are cut out of the graph. I'd like to make it so that in the left part of the graph labels are in the right side of the point they are marking, and in the right part of the graph labels on the left side of the point.

The graph looks like:

enter image description here

The code for the labels is:

text = chart.mark_text(
      align='left',
      baseline='middle',
      dx=7
  ).encode(
      text='System',
      color=alt.Color('Domain', 
                      legend=None,
                      scale=alt.Scale(
                         domain=['Large Scale'],
                         range=['red'])
                      ),
  )

chart = (chart + text).resolve_scale(shape='independent', color='independent')

Is there an easy way to achieve this?

0 Answers
Related