我想知道如何从文本文件中仅提取数字数据并读取它的过程。我有一个名为 temperature.txt 的文本文件,它不断在模拟我的代码时附加数据。我想知道 javascript 中的代码以将数据实时流式传输到 plotly。
'use strict';
var plotly = require('plotly')('agni_2006','jtwubwfjtp');
var initdata = [{x:[], y:[], stream:{token:'g1z4cinzke', maxpoints:200}}];
var initlayout = {fileopt : 'overwrite', filename : 'try'};
plotly.plot(initdata, initlayout, function (err, msg) {
if (err) return console.log(err);
console.log(msg);
var stream1 = plotly.stream('g1z4cinzke', function (err, res) {
if (err) return console.log(err);
console.log(res);
clearInterval(loop); // once stream is closed, stop writing
});
var i = 0;
var loop = setInterval(function () {
var data = { x : i, y : …Run Code Online (Sandbox Code Playgroud) 我正在使用 Plotly 库来创建我的数据图表。我遇到的问题是,当我尝试在不同的选项卡中将它们分开时,它不会像预期的那样调整大小(仅使用高度,宽度可以),除了第一个选项卡的图表,它工作正常。
在我的 index.html 中,我有以下结构:
<script type="text/javascript" src="{{STATIC_URL}}myindex.js"></script>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#var1">Var 1</a></li>
<li><a data-toggle="tab" href="#var2">Var 2</a></li>
</ul>
<div class="tab-content">
<div id="var1" class="tab-pane fade in active">
<div class="thumbnail parent_container" style="margin-top: 100px;">
<div class="thumbnail text-center chart">
<div id="chart1">
</div>
</div>
...
</div>
</div>
<div id="var2" class="tab-pane fade">
<div class="thumbnail parent_container" style="margin-top: 100px;">
<div class="thumbnail text-center chart">
<div id="chart2">
</div>
</div>
...
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
必须创建图表的 myindex.js 部分如下所示:
$( document ).ready(function()
{
"use strict";
var WIDTH_IN_PERCENT_OF_PARENT = 96; …Run Code Online (Sandbox Code Playgroud) 以下代码根据分层聚类(使用hclust()和cutree())创建一个Choropleth地图:
library(plotly)
library(cluster)
hc <- hclust(dist(df), method = "complete")
df$member <- cutree(hc, 5)
cluster.means = (as.data.frame(aggregate(df[,-1], list(cluster= df$member), mean)))[,-4]
g = list(
scope = 'africa',
showframe = T,
showland = T,
landcolor = toRGB("white")
)
plot_ly(df, z = member, type = 'choropleth', locations = Country,
locationmode = 'country names', text = Country, hoverinfo = "text") %>%
layout(geo = g, title = "Energy markets in Africa")
Run Code Online (Sandbox Code Playgroud)
现在我想改变两件事:
cluster.means我附上了这样一个关于我的想法的示例性情节(它不必看起来完全相同 …
在这个页面上,在情节上暗示他们有一些默认的色标,例如"Viridis".我不能为我的生活找到一个记录这些命名色标的网页.
我正在按照教程的时间序列,在这里.我还修改了代码,允许在Jupyter离线图表,在这里.
我正试图在Jupyter Notebook中绘制一个时间序列.我收到以下错误.
AttributeError:模块'plotly.plotly'没有属性'离线'
据我所知,我已经执行了所有说明,但无法使用他们建议的方法.
import plotly.plotly as py
import plotly.graph_objs as go
py.offline.init_notebook_mode()
data = [go.Scatter(x=dataload.date, y=dataload.spend)]
py.offline.iplot(data)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-14-c9b2e8d8907c> in <module>()
2 import plotly.graph_objs as go
3
----> 4 py.offline.init_notebook_mode()
5
6 data = [go.Scatter(x=dataload.date, y=dataload.spend)]
AttributeError: module 'plotly.plotly' has no attribute 'offline'
Run Code Online (Sandbox Code Playgroud)
有没有人建议我为什么会收到此错误,这可能是本地设置问题?
我有一个.Net应用程序,我正在尝试使用bootstrap.js和创建图形plotly.js.
当我创建响应式图表时,我的网格中存在巨大的空白区域问题.我已经发现问题的一部分是剧情svg-container的大小默认为450px的高度.
我创造了一个小提琴,展示了巨大的空白问题.
在我的小提琴中,我有一个小的注释代码块来设置布局大小,但即使设置这似乎也没有帮助删除大部分空白区域.此外,如果它变得太小,它会开始裁掉一些图表.
//can adjust size of svg-container
//but doesn't adjust white space
//var layout = {
// height: 350
//}
//Plotly.plot(gd, pieData, layout);
Run Code Online (Sandbox Code Playgroud)
正如你可能已经猜到的那样,我想让它更小 - 删除相当一些的空白区域,以便下面的表格看起来不那么不合适.
我想知道是否有一种方法可以为plotly的饼图提供自定义图标,而不是通常的饼图分区
到目前为止,我正在使用饼图显示性别信息,该饼图如下所示:
我正在尝试使其看起来像下面链接中的性别图:
绘图代码如下:
plot_ly(genderselection, labels = ~Gender, values = ~Freq, type = 'pie') %>%
layout(title = paste0("Gender Distribution of Patients from Boston"),
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
legend=list(orientation='h'))
Run Code Online (Sandbox Code Playgroud)
性别选择数据框:
Gender Freq
F 70
M 65
Run Code Online (Sandbox Code Playgroud)
如果不使用plotly,是否还有其他库可用于使用自定义图标显示信息?
我想用plotly创建一个概率密度矩阵的热图.
import numpy as np
from plotly.offline import download_plotlyjs, init_notebook_mode, plot
import plotly.graph_objs as go
probability_matrix = np.loadtxt("/path/to/file")
trace = go.Heatmap(z = probability_matrix)
data=[trace]
plot(data, filename='basic-heatmap')
Run Code Online (Sandbox Code Playgroud)
这给了我一个像这样的图像:
我想平滑正方形的颜色,以便图像中相邻正方形之间的过渡有点"平滑".我想知道是否有办法做到这一点,而无需使用插值手动调整矩阵大小.
我在中生成了相关的热图plotly。比例尺范围从-1到1。随着相关性的增强,图块将变深红色。随着相关性变得越来越弱,图块会被涂成深蓝色。我需要零值才能显示为白色。但是,色条仅根据数据集的分布选择零色。如何强制零值显示为白色并位于颜色栏的中间?我尝试使用此答案,但无法使其适用于此热图。请帮我生气!
library(plotly)
library(magrittr)
# compute a correlation matrix
correlation <- round(cor(mtcars), 3)
nms <- names(mtcars)
colorlength <- 100
null_value <- (0 - min(correlation)) / (max(correlation) - min(correlation))
border <- as.integer(null_value * colorlength)
colorscale <- as.list(1:colorlength)
#colorscale below zero
s <- scales::seq_gradient_pal("blue", "white", "Lab")(seq(0,1,length.out=border))
for (i in 1:border) {
colorscale[[i]] <- c((i - 1) / colorlength, s[i])
}
#colorscale above zero
s <- scales::seq_gradient_pal("white", "red", "Lab")(seq(0,1,length.out=colorlength - border))
for (i in 1:(colorlength - border)) {
colorscale[[i + …Run Code Online (Sandbox Code Playgroud) plotly ×10
r ×4
javascript ×3
heatmap ×2
choropleth ×1
colors ×1
correlation ×1
css ×1
ggplot2 ×1
ggplotly ×1
graph ×1
grid-layout ×1
html ×1
jquery ×1
legend ×1
node.js ×1
python ×1
shiny ×1
smoothing ×1