- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在处理这个例子中的代码,稍作修改:
https://altair-viz.github.io/gallery/layered_heatmap_text.html
我试图找出为什么当我尝试分面到列时我的代码会中断。
# Import data
import altair as alt
from vega_datasets import data
source = data.cars()
# Configure common options
base = alt.Chart(source)
scale = alt.Scale(paddingInner=0)
原始版本工作正常:
# Configure heatmap
heatmap = base.mark_rect().encode(
alt.X('Cylinders:O', scale=scale),
alt.Y('Year:O', scale=scale),
color='count()'
)
# Configure text
text = base.mark_text(baseline='middle').encode(
x='Cylinders:O',
y='Year:O',
text='count()',
color=alt.value('white')
)
# Draw the chart
heatmap+text
现在我想按 Origin
分面。当我分别显示 heatmap
和 text
时,下面的代码有效,但是当我组合它们时,出现错误。
# Configure heatmap
heatmap = base.mark_rect().encode(
alt.X('Cylinders:O', scale=scale),
alt.Y('Year:O', scale=scale),
color='count()',
column = 'Origin'
)
# Configure text
text = base.mark_text(baseline='middle').encode(
x='Cylinders:O',
y='Year:O',
text='count()',
color=alt.value('white'),
column = 'Origin'
)
# Draw the chart
heatmap+text
这是错误消息 - 我不太明白问题出在哪里。
---------------------------------------------------------------------------
SchemaValidationError Traceback (most recent call last)
~/miniconda3/lib/python3.6/site-packages/altair/vegalite/v2/api.py in _repr_mimebundle_(self, include, exclude)
1111 try:
-> 1112 dct = self.to_dict()
1113 except Exception:
~/miniconda3/lib/python3.6/site-packages/altair/vegalite/v2/api.py in to_dict(self, *args, **kwargs)
420 kwargs['validate'] = 'deep'
--> 421 dct = super(TopLevelMixin, copy).to_dict(*args, **kwargs)
422
~/miniconda3/lib/python3.6/site-packages/altair/utils/schemapi.py in to_dict(self, validate, ignore, context)
253 except jsonschema.ValidationError as err:
--> 254 raise SchemaValidationError(self, err)
255 return result
<class 'str'>: (<class 'TypeError'>, TypeError('sequence item 1: expected str instance, int found',))
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
~/miniconda3/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj, include, exclude)
968
969 if method is not None:
--> 970 return method(include=include, exclude=exclude)
971 return None
972 else:
~/miniconda3/lib/python3.6/site-packages/altair/vegalite/v2/api.py in _repr_mimebundle_(self, include, exclude)
1112 dct = self.to_dict()
1113 except Exception:
-> 1114 utils.display_traceback(in_ipython=True)
1115 return {}
1116 else:
~/miniconda3/lib/python3.6/site-packages/altair/utils/core.py in display_traceback(in_ipython)
403
404 if ip is not None:
--> 405 ip.showtraceback(exc_info)
406 else:
407 traceback.print_exception(*exc_info)
~/miniconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in showtraceback(self, exc_tuple, filename, tb_offset, exception_only, running_compiled_code)
2036 value, tb, tb_offset=tb_offset)
2037
-> 2038 self._showtraceback(etype, value, stb)
2039 if self.call_pdb:
2040 # drop into debugger
~/miniconda3/lib/python3.6/site-packages/ipykernel/zmqshell.py in _showtraceback(self, etype, evalue, stb)
544 u'traceback' : stb,
545 u'ename' : unicode_type(etype.__name__),
--> 546 u'evalue' : py3compat.safe_unicode(evalue),
547 }
548
~/miniconda3/lib/python3.6/site-packages/ipython_genutils/py3compat.py in safe_unicode(e)
63 """
64 try:
---> 65 return unicode_type(e)
66 except UnicodeError:
67 pass
~/miniconda3/lib/python3.6/site-packages/altair/utils/schemapi.py in __unicode__(self)
67 schema_path = ['{}.{}'.format(cls.__module__, cls.__name__)]
68 schema_path.extend(self.schema_path)
---> 69 schema_path = '->'.join(val for val in schema_path[:-1]
70 if val not in ('properties',
71 'additionalProperties',
TypeError: sequence item 1: expected str instance, int found
最佳答案
问题是分面图表不能分层(这是因为一般来说,不能保证两层会有兼容的分面)。另一方面,分层图表可以是分面的。例如:
# Import data
import altair as alt
from vega_datasets import data
source = data.cars()
# Configure common options
scale = alt.Scale(paddingInner=0)
# Configure heatmap
heatmap = alt.Chart().mark_rect().encode(
alt.X('Cylinders:O', scale=scale),
alt.Y('Year:O', scale=scale),
color='count()'
)
# Configure text
text = alt.Chart().mark_text(baseline='middle').encode(
x='Cylinders:O',
y='Year:O',
text='count()',
color=alt.value('white')
)
# Draw the chart.
alt.layer(heatmap, text, data=source).facet(
column='Origin'
)
请注意,使用此方法时,重要的是在构面级别而不是子层中指定数据。有关详细信息,请参阅 Faceted Charts在 Altair 文档中。
这里的错误消息过去更有帮助...似乎 jsonschema
库报告模式验证错误的方式与以前不同。
关于python - 将文本和数据图表与 facet 结合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55007597/
我有一张 Excel 表格,用于更新玩家评分。 播放器 配售 初始化 1 2 3 4 金融评级 一个 1 2.0 1.000 0.018 0.016 0.014 2.007 D 2 -2.0 54.5
我有一个 map = std::map ,其中 myItemModel继承QAbstractItemModel . 我现在要合并所有 myItemModel合一myItemModel (其他所有元素模
我大量使用“do.call”来生成函数调用。例如: myfun <- "rnorm"; myargs <- list(n=10, mean=5); do.call(myfun, myargs); 但是
想象一下 InputStream 的以下变体: trait FutureInputStream { //read bytes asynchronously. Empty array means E
这是我的 C 代码: #include void sum(); int newAlphabet; int main(void) { sum();
我只是想选择类“.last”之后的每个元素。 HTML: 1 2 Jquery
我正在为一个项目构建一个 XML 反序列化器,我经常遇到这种类型的代码情况: var myVariable = ParseNDecimal(xml.Element("myElement")) == n
这是来自 Selecting the highest salary 的继续问题 假设有一个表 'wagetable' name lowhours highhours wage pri
我正在为我的程序创建一个战舰程序;该程序运行良好,但我试图确保当用户将坐标超出范围时,程序会说他们输入的坐标不正确。这是代码: #include #include void
我有一个函数,它为每种情况返回不同的 DWORD 值,如果出现错误。所以我有以下定义: #define ERR_NO_DB_CONNECTION 0x90000 #define ERR_DB_N
在派生类中引发基类事件以下简单示例演示了在基类中声明可从派生类引发的事件的标准方法。此模式广泛应用于 .NET Framework 类库中的 Windows 窗体类。在创建可用作其他类的基类的类时,应
我只是想知道这是否可能: use Modern::Perl; my @list = ('a' .. 'j'); map { func($_) } each(@list); sub func { m
我一直在使用 =IF(L2="","Active",IF(K2I2,"Late"))) 有效,但现在我需要检查 F 上的多个条件 专栏 我试过了 OR 函数 =IF(OR(F2="Scheduled"
我有 2 个命令,如下所示。 在视频中添加介绍图片 ffmpeg -y -loop 1 -framerate 10 -t 3 -i intro.png -i video.mp4 -filter_com
好的,我有这个公式可以根据名字和姓氏列表生成用户名。现在,虽然这可行,但我希望单元格改为引用我自己的 VBA 函数。但是,由于代码少得多,我仍然想使用原始公式。 我有这个公式: =SUBSTITUTE
我有两个 HAProxy 实例。两个实例都启用了统计信息并且工作正常。 我正在尝试将两个实例的统计信息合并为一个,以便我可以使用单个 HAProxy 来查看前端/后端统计信息。我试图让两个 hapro
我有一个 Observable,其中每个新值都应该引起一个 HTTP 请求。在客户端,我只关心最新的响应值;但是,我希望每个请求都能完成以进行监控/等。目的。 我目前拥有的是这样的: function
我的网站上有 TinyMCE 插件。在 TinyMCE 插件的 textarea 中添加图像时,我希望这些图像包含延迟加载。我网站的缩略图具有特定类型的延迟加载,其中 src 图像是灰色背景。根据用户
我希望合并润滑间隔,以便如果它们重叠,则从内部第一个时间获取最小值和从内部最后一个时间获取最大值并总结以创建一个跨越整个时间段的新间隔。这是一个reprex: library(lubridate, w
我有一个应用程序,它本质上是一个页眉、主要内容和一个始终可见的页脚。页脚可以改变大小,我想在页脚上方的主内容面板上放置一些工具。主要布局是用 flex 完成的,我阅读文档的理解是绝对定位通过相对于最近
我是一名优秀的程序员,十分优秀!