Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Altair change the orientation of column labels

This plot has dates across the top of the columns. They flow over each other making them difficult to read. Is there a way to rotate these vertically? I could not find the solution online.

rr_st = alt.Chart(dfag).mark_bar().encode(
    x=alt.X('rebalance_range:O', title=""),
    y=alt.Y('mean(annual_return):Q', title='annual return'),
    column= alt.Column('start_date', title=""), 
    color=alt.Color('rebalance_range:O', title='rebalance range')
)

rr_st 

enter image description here

like image 890
run-out Avatar asked Apr 22 '19 16:04

run-out


People also ask

How do I change the orientation of a label?

Change Text Direction Using A Text Box Select the text orientation you need and select okay. b) left click inside the text box, then right click, and select “Borders and Alignment” from the options that appear. Select the text orientation you need and select okay.

How do I remove the grid from Altair?

We can remove the grid lines on x or y-axis by specifying the argument grid=False inside alt. X() or alt. Y() method in the encoding channels.


Video Answer


1 Answers

These are the labels for the column header; as such you can use Header(labelAngle) within the column encoding:

alt.Chart(dfag).mark_bar().encode(
    x=alt.X('rebalance_range:O', title=""),
    y=alt.Y('mean(annual_return):Q', title='annual return'),
    column= alt.Column('start_date',
        title="",
        header=alt.Header(labelAngle=90)
    ), 
    color=alt.Color('rebalance_range:O', title='rebalance range')
)
like image 167
jakevdp Avatar answered Sep 24 '22 09:09

jakevdp