如何从离线的可打印python jupyter笔记本中的选定点获取数据?

d格罗夫

示例代码:

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

import plotly.graph_objs as go

import numpy as np

N = 30
random_x = np.random.randn(N)
random_y = np.random.randn(N)

# Create a trace
trace = go.Scatter(
    x = random_x,
    y = random_y,
    mode = 'markers'
)

data = [trace]

# Plot and embed in ipython notebook!
iplot(data, filename='basic-scatter')

[ 在此处输入图片说明]

如何从选择中获得x,y数据或索引的副本?

纳伦·穆拉利

因此,如果您想在Jupyter笔记本中使用javascript,则有两种选择。

使用以下display(HTML())方法在jupyter笔记本中呈现html,下面的示例代码中演示了该方法!

另一种方法是使用IPython Magic,在这里阅读更多,代码将像这样。

%% html
%html [--isolated]将单元格渲染为HTML块

可选参数:--isolated将单元格注释为“ isolated”。隔离的单元格呈现在其自己的标签内

%%html
<span> naren</span>

您也可以使用上述方法来呈现HTML。

请检查下面的代码,我select event可口的javascript事件文档中获取了代码,并使其适用于jupyter!

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.graph_objs as go
from plotly import tools
import pandas as pd
import numpy as np
from datetime import datetime
init_notebook_mode(connected=True)
from IPython.core.display import display, HTML


N = 30
random_x = np.random.randn(N)
random_y = np.random.randn(N)

# Create a trace
trace = go.Scatter(
    x = random_x,
    y = random_y,
    mode = 'markers'
)

data = [trace]

# Plot and embed in ipython notebook!
plot = plot(data, filename='basic-scatter', include_plotlyjs=False, output_type='div')
divId=plot.split("id=\"",1)[1].split('"',1)[0]
plot = plot.replace("Plotly.newPlot", "var graph = Plotly.newPlot")
plot = plot.replace("</script>", """
var graph = document.getElementById('"""+divId+"""');
var color1 = '#7b3294';
var color1Light = '#c2a5cf';
var colorX = '#ffa7b5';
var colorY = '#fdae61';
;graph.on('plotly_selected', function(eventData) {
  var x = [];
  var y = [];

  var colors = [];
  for(var i = 0; i < N; i++) colors.push(color1Light);

  eventData.points.forEach(function(pt) {
    x.push(pt.x);
    y.push(pt.y);
    colors[pt.pointNumber] = color1;
  });


  Plotly.restyle(graph, 'marker.color', [colors], [0]);
});
""")
display(HTML(plot))

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从Jupyter笔记本中获取原始代码?

在jupyter笔记本python中密谋

如何在python中获取当前的jupyter笔记本服务器?

对于分类数据,如何在表而不是列表中显示结果?(Jupyter笔记本/ Python)

如何从Jupyter笔记本中的Tkinter文本小部件中获取文本?

如何!rm python_var(在Jupyter笔记本中)

jupyter笔记本中的打印顺序

在Jupyter笔记本中打印多行字符串

在Jupyter笔记本中自定义打印

在 Jupyter 笔记本中使用 Python 从 github 导入数据

Jupyter可以在Python笔记本中运行单独的R笔记本吗?

如何使用 Jupyter 笔记本打印出 Pandas 中 csv 文件中的每个数据值

Python 中的缩进错误(在 Jupyter 笔记本中)

如何从 Azure 数据块获取 python 笔记本路径?

如何检查您是否在Jupyter笔记本中

如何在Jupyter笔记本中嵌入gif?

如何在Jupyter笔记本中包装代码/文本

如何在Jupyter笔记本中配置缩进大小?

如何在Jupyter笔记本中对熊猫使用tqdm?

如何在jupyter笔记本中安装sympy

如何从笔记本中查找Jupyter Notebook版本

如何从Jupyter笔记本中删除emacs键绑定?

如何在Pycharm笔记本中停止Jupyter Server

在jupyter笔记本中创建原始python文件

在Jupyter Python笔记本中清除MatPlotLib图

如何根据python中pandas数据框中的列进行分组并按降序排列?(Jupyter笔记本)

如何撤消/重做 Jupyter 笔记本中选定单元格内的更改?

如何快速从Google Cloud Datalab笔记本中获取数据?

如何将jupyter笔记本目录中的模块导入较低目录中的笔记本?