简体   繁体   中英

Make bar chart's x-axis markers horizontal or 45 degree readable in Python Altair

I am trying to create a bar chart with year data on x-axis. It works but the year marker on x-xais are all in vertical direction and I want to make them more readable - either horizontal or 45 degree. I tried using the year:T in datatime format but it gave me the year and month markers (I just wanted to have the year markers on xais). How do I make the year markers on x-axis either horizontal or 45 degree?

import altair as alt
from vega_datasets import data

source = data.wheat()
source.info()

abars = alt.Chart(source).mark_bar().encode(
    x='year:O',
    y="wheat:Q"
)

在此处输入图像描述

Set labelAngle :

alt.Chart(source).mark_bar().encode(
    x=alt.X('year:O', axis=alt.Axis(labelAngle=-45)),
    y="wheat:Q"
)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM