我有一个数据集,我想在 X 轴上绘制具有 2 个不同变量的绘图(在 2 个不同的图中),但我想将其他值放入 Hovertool
from io import StringIO
import pandas as pd
data = """,item_id,start,station,rejects
0,item1,2019-10-14 19:00:00,assembly,4.297994269340974
1,item1,2019-10-14 19:00:00,ST1,0.20546537908362442
2,item1,2019-10-14 19:00:00,ST2,0.494539460127756
3,item1,2019-10-14 19:00:00,ST3,0.6892230576441103
4,item2,2019-10-14 23:30:00,assembly,4.432249894470241
5,item2,2019-10-14 23:30:00,ST1,0.19071837253655435
6,item2,2019-10-14 23:30:00,ST2,0.7651434643995749
7,item2,2019-10-14 23:30:00,ST3,0.7748600947051227
8,item3,2019-10-15 04:00:00,assembly,3.55576079427384
9,item3,2019-10-15 04:00:00,ST1,0.37002775208140615
10,item3,2019-10-19 04:00:00,ST2,0.7195914577530177
11,item3,2019-10-19 04:00:00,ST3,0.492379835873388
12,item4,2019-10-19 10:30:00,assembly,4.02656704026567
13,item4,2019-10-19 10:30:00,ST1,0.22926219258024177
14,item4,2019-10-19 10:30:00,ST2,0.690376569037657
15,item4,2019-10-19 10:30:00,ST3,0.838745695410320"""
data_reduced = pd.read_csv(StringIO(data), parse_dates=["start"], index_col=0)
Run Code Online (Sandbox Code Playgroud)
我想生成一个图表,其中item_idx 轴为 ,startx 轴为日期。我想跟踪每个站的废品以及装配的组合。
import holoviews as hv
import bokeh
from holoviews import opts
hv.extension('bokeh')
bokeh.plotting.output_notebook()
def plot(data_reduced, x_axis="item_id"):
x_label …Run Code Online (Sandbox Code Playgroud) 我有一个散景图,我以LabelSet和BoxAnnotation的形式添加一些数据作为叠加,但我希望能够动态启用/禁用此叠加.
我可以启用/隐藏在一些情节的线条已经,但对于标注系统似乎是不同的.我已经到目前为止了
from ipywidgets import interact
from bokeh.plotting import figure as bf
from bokeh.layouts import layout as bl
from bokeh.models import Toggle, BoxAnnotation, CustomJS
from bokeh.io import push_notebook, show, output_notebook
output_notebook()
Run Code Online (Sandbox Code Playgroud)
p = bf(title='test', x_range=(0,1), y_range=(0,1))
x = [1/3, 2/3]
y=[1/3, 2/3]
p.circle(x=x, y=y, size=15)
box = BoxAnnotation(left=None, right=0.5, fill_color='red', fill_alpha=0.1)
p.add_layout(box)
Run Code Online (Sandbox Code Playgroud)
code = '''\
if toggle.active
box.visible = true
console.log 'enabling box'
else
box.visible = false
console.log 'disabling box'
'''
callback = CustomJS.from_coffeescript(code=code, args={}) …Run Code Online (Sandbox Code Playgroud) 我想写一个函数,它接受一个数字和列表列表,它们也可以包含数字和列表,依此类推......,并返回列表中某处的总数量.
示例:[1,[[[0,2],7,3],5,[1,2]],3]其中包含9个数字.
到目前为止这是我的代码:
test=[1,[[[0,2],7,3],5,[1,2]],3]
def flatten(mylist):
counter = 0
for i in range(len(mylist)):
if type(mylist[i]) == int:
counter += 1
if type(mylist[i]) == list:
[item for sublist in mylist[i] for item in sublist]
counter += 1
return counter
Run Code Online (Sandbox Code Playgroud)
我想我需要recursivley压扁子列表.但我得到错误:TypeError: 'int' object is not iterable