python - How can I match the scale for 2 different variables in mark_circle() in Altair?
问题描述
I'm working with Altair and I'm having trouble overlapping 2 mark_circle() charts due to the size of my variables. I want to overlay 2 circles so I can compare the size of one variable to the size of the other variable.
The problem is that one variable is in the order of millions and the second variable is from 0 to 100 and when overlapping them the second variable is not shown due to the size compared to millions.
I tried playing with scale=alt.Scale(range=(xx,xx)) but I can't make it work, so not sure if this is possible or where am I getting lost?
Here is my code
pop = alt.Chart(df).mark_circle(color='blue').encode(
y = alt.Y('Top_City', sort=alt.SortField(field="Rank_mean", order='ascending')),
size = alt.Size('Pop_mean')
)
pop
fa = alt.Chart(df).mark_circle(color='yellow').encode(
y = alt.Y('Top_City', sort=alt.SortField(field="Rank_mean", order='ascending')),
size = alt.Size('FARS_PerCapita')
)
fa
Ideally I would like to have something like the last image when doing
pop + fa
解决方案
After staring at it for an extended period of time this solved my problem.
alt.layer(pop, fa).resolve_scale(size='independent')
推荐阅读
- powershell - Powershell Invoke-Command 失败,在本地可以正常工作
- sql-server - 来自其他表的计算列作为主键 SQL Server
- java - 通过终端在 open-liberty 上手动启动服务器
- python - LeetCode 的 Coin Change 问题超过了时间限制
- c# - 如何使用 UWP XAML C# 将图像添加到图像中?
- oracle - OSB 警报配置 - 11g
- php - Wordpress Groups 插件:如果私有,子页面不显示
- javascript - 如何在 AJAX 中使用 PUT 更新记录
- android - 无法通过 NFC 发送 NDEF 消息
- sql - 在使用交叉表中解决此查询