python - Altair-即重复和变换
问题描述
有没有办法使用重复图表使用的编码来应用数据转换或过滤?
如果我对文档的理解正确,它似乎是不可能的:
当前只能为行和列指定重复(例如,不能为层指定),并且目标只能是编码(例如,不能是数据转换),但是 Vega-Lite 社区内部正在讨论如何使这种模式在未来。
有什么好的方法可以解决这个问题?例如下面,假设我只想绘制y>0
(或者可能是另一个变换,我不想只在 y 轴上缩放)的点。有没有办法使用重复目标来应用类似于第 0 行的东西(如第 1 行中所尝试的那样,但失败了TypeError: '>' not supported between instances of 'RepeatRef' and 'float'
)?
import altair as alt
import numpy as np
import pandas as pd
x = np.arange(100)
source = pd.DataFrame({
'x': x,
'f': np.sin(x / 5),
'g': np.cos(x / 3),
})
alt.Chart(source).mark_line().encode(
alt.X('x', type='quantitative'),
alt.Y(alt.repeat('column'), type='quantitative'),
).transform_filter(
# alt.datum.f >= 0. #0 Works, but would like to use f or g depending on the plotted variable
alt.repeat('column') > 0. #1 ERROR HERE
).repeat(
column=['f', 'g']
)
解决方案
推荐阅读
- angular - 如何为绑定制作原始类型引用
- shell - 从文本文件中逐行读取并在 shell 脚本中打印我想要的方式
- php - How to fix Wordpress pagination (page not found after 8th page)
- wordpress - 如何禁止一个国家/地区评估没有插件的 Wordpress 网站
- c# - 如果包含格式/值,如 (1753-01-01) - MVC,如何不显示日期时间的值
- go - 在 vs 代码中调试 golang 期间 Delve 无法正常工作
- python - 以最小速率重塑 numpy 数组
- java - org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException:在自动发现本机 sql 查询期间遇到重复的 sql 别名 []
- oracle - 如何编写一个plsql程序来生成带有查询数据的excel?
- mysql - 如何使用 MYSQL 计算选择查询的两列值?