小编p_m*_*_mo的帖子

配置 Altair 图表的标题和轴

我最近正在学习如何使用 Altair 创建图表,但在自定义标题和轴时遇到了一些问题。我的图表代码目前如下所示:

chart = Chart(data).mark_bar().encode(
    column='Cell Type',
    x='Truth/Pred',
    y='03',
    color='Truth/Pred',
).properties(
    title='Truth vs Predictions for Cell Type Percentages'
).configure_axisBottom(
    disable = True
).configure_axisTop(
    # labelPadding = 100
    orientation = "bottom"
).configure_axisY(
    title = "Cell Type Percentages"
)

chart.display()
Run Code Online (Sandbox Code Playgroud)

图表如下所示: 由上面的代码生成的图表

我有几个问题。

有没有办法让标题居中?

其次,我试图将 Y 轴设置为“单元格类型百分比”,但似乎没有 Y 轴,我不确定为什么。

最后,我尝试将顶部轴移至底部,并将标签稍微隔开一点,或旋转它们,使它们不会彼此重叠。然而,配置 axisTop 参数似乎根本不影响 Cell Type 轴!我也不确定为什么会这样。

我尝试遵循此堆栈溢出问题的答案:链接到相关问题

但我总是收到错误说明"additional properties are not allowed",所以我不确定他们是否停止在构造函数中使用配置属性。

任何帮助表示赞赏。谢谢你!

data-visualization altair grouped-bar-chart

4
推荐指数
1
解决办法
4200
查看次数