How do you set Axis FontSize in Altair?

荒凉一梦 提交于 2019-12-01 05:36:02

问题


I would like to increase the X-Axis (or Y-Axis for that matter) fontSize to 16 (or any value) in the following Altair graph. I could not find any example in the Altair documentation here: https://altair-viz.github.io/index.html. I am using Jupyter Lab for visualization. Intuitively alt.Axis should take FontSize argument

import altair as alt
from vega_datasets import data
cars = data.cars()

alt.Chart(cars).mark_point().encode(
    alt.X('Horsepower', axis=alt.Axis(title="HORSEPOWER")),
    alt.Y('Miles_per_Gallon', axis=alt.Axis(title="Miles Per Gallon")),
    color='Origin',
    shape='Origin'
)

enter image description here


回答1:


One way you can do this is using the top-level chart configuration (think of it as a set of default chart properties). For example:

import altair as alt
from vega_datasets import data
cars = data.cars()

alt.Chart(cars).mark_point().encode(
    alt.X('Horsepower', axis=alt.Axis(title="HORSEPOWER")),
    alt.Y('Miles_per_Gallon', axis=alt.Axis(title="Miles Per Gallon")),
    color='Origin',
    shape='Origin'
).configure_axis(
    labelFontSize=20,
    titleFontSize=20
)

You can read more in Altair's Chart Configuration documentation.



来源:https://stackoverflow.com/questions/53401693/how-do-you-set-axis-fontsize-in-altair

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!