如何用plotly包得到虚线趋势线?根据文档,应该是:
dat <- iris[,2:3]
colnames(dat) <- c("x","y")
p <- plot_ly(dat, x = x, y = y, type="scatter", mode="markers", name="data")
add_trace(p, x = x, y = fitted(lm(y~x, data=dat)), line = list(dash="dashed"), name="regression line")
Run Code Online (Sandbox Code Playgroud)
但趋势线是稳固的。
plotly的文档说,通过参数range我们可以设置轴的限制,例如range = [0, 10]将轴最小值设置为0,最大值设置为10。根据文档,它可以在figure、layout、scene或xaxis下使用。事实上Scatter,andLayout接受xaxis和yaxis参数,它们要么是字典,要么是plotly.graph_objs.XAxis对象,并且可以提供一个range值。然而,在尝试了我能想象到的所有变化后,它显然未能设定限制。此外,第一个子图似乎低于其他子图。请参阅下面的最小工作示例,它可以在任何 Jupyter 笔记本中运行。
额外问题:为什么fill参数 atScatter无法设置点的填充颜色?
import plotly
import plotly.tools
import plotly.graph_objs
plotly.offline.init_notebook_mode()
data = {
'A': {
'x': [1.0, 2.0, 6.0, 8.0],
'y': [34.0, 36.0, 38.0, 40.0],
's': [0.00416, 0.01125, 0.0038, 0.002]
},
'B': {
'x': [1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 3.0, 2.0, 2.0, 3.0,
4.0, 2.0, 4.0, 5.0, 6.0, 7.0, 7.0],
'y': [30.0, 32.0, …Run Code Online (Sandbox Code Playgroud) 我正在使用plotly.js 创建图表。有些图表的图例内有很长的文本,因此这些文本使图例不必要变大。我想给图例固定宽度,如果文本长度很长,我希望它被换行。
我一直试图通过操作 DOM 上的 svg 元素来做到这一点,但由于图例是svg:g标签,所以我真的不能做太多事情。我也尝试 Give textLengthto <text>,但它确实会换行文本,但不会换行。
有没有办法给图例固定宽度?
我一直在尝试使用绘图和串扰库生成交互式链接可视化。如下例所示,似乎可以向 ggplot2 传递一个“共享数据框”对象,以便使用 ggplotly() 生成链接视图。当我尝试运行此示例时,我收到以下错误消息:
错误:ggplot2 不知道如何处理 SharedData/R6 类的数据
我正在使用当前版本的 ggplot2 (v. 2.2.1) 和plotly (4.5.6)。什么可能导致此错误?
谢谢帮助!
我试图复制的示例可以在这里找到:
https://cpsievert.github.io/plotly_book/linking-animated-views.html
library(gapminder)
library(crosstalk)
library(ggplot2)
library(plotly)
g <- crosstalk::SharedData$new(gapminder, ~continent)
gg <- ggplot(g, aes(gdpPercap, lifeExp, color = continent, frame = year)) +
geom_point(aes(size = pop, ids = country)) +
geom_smooth(se = FALSE, method = "lm") +
scale_x_log10()
ggplotly(gg) %>%
highlight("plotly_hover")
Error: ggplot2 doesn't know how to deal with data of class SharedData/R6
Run Code Online (Sandbox Code Playgroud) 简而言之:使用R和Plotly包,我可以创建一个覆盖条形图,其中使用 x 轴上的相同位置显示 2 个系列吗?经过相当多的谷歌搜索后,我找不到答案。
例如这个可视化:
使用 Plotly 和 R 创建分组(非重叠)堆叠条形图的代码:
months = 1:12
n1 = runif(12, min = 0, max = 1)
n2 = runif(12, min = 0, max = 1)
dfPlot = data.frame(months, n1, n2)
plot_ly(x = dfPlot [,1],
y = dfPlot [,2],
type = 'bar') %>%
add_trace(x = dfPlot[,1],
y = dfPlot[,3],
type = 'bar')
Run Code Online (Sandbox Code Playgroud)
如何调整图表以使系列重叠?关于如何以类似的方式可视化相同信息但具有不同逻辑的建议也非常感谢!
我正在尝试在 React 中导入 D3v4 来生成 Dash 组件。到目前为止,这是我的代码:
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import * as d3 from 'd3';
function createBox(divId) {
var svgContainer = d3.select(divId).append('svg')
.attr('width', 200)
.attr('height', 200);
//Draw the Circle
svgContainer.append('circle')
.attr('cx', 30)
.attr('cy', 30)
.attr('r', 20);
}
/**
* ExampleComponent is an example component.
* It takes a property, `label`, and
* displays it.
* It renders an input with the property `value`
* which is editable by the user.
*/
export default …Run Code Online (Sandbox Code Playgroud) 我正在尝试将多个图表合并成一个 HTML 报告来发送。问题是我真的不认为子图是最好的主意,因为图表相对不相关(不同的 X/Y 轴)。我所需要做的只是将图表附加到 1 个 HTML 文件中。有一个指南解释了如何使用绘图 URL 来完成此操作,但我不想依赖互联网连接来进行自动报告,并且我希望能够在线查看这些报告
我正在尝试创建一个 HTML 报告,该报告只是将多个绘图添加到一个 HTML 文件中,而不是拥有多个单独的 HTML 文件。这些图表并不真正相关,因此对创建子图不感兴趣。理论上它只是一个 HTML 文件,所以我可以以某种方式复制并粘贴代码并让它们都显示出来,对吧?
我指的文档: https: //plot.ly/python/html-reports/
在绘制数据的正态分布图时,我们如何使用 matplotlib/seaborn 或plotly 为每个箱中的数据百分比添加如下图所示的标签,其中每个波段的宽度为 1 个标准差?
目前,我正在绘制这样的图:
hmean = np.mean(data)
hstd = np.std(data)
pdf = stats.norm.pdf(data, hmean, hstd)
plt.plot(data, pdf)
Run Code Online (Sandbox Code Playgroud)
我有一个图,其中第一条迹线为灰色,该迹线将被其他颜色的迹线覆盖。我的问题是在plotly4.7.1 版本中。以及 4.8.0 版本。我无法调整颜色。
一年前这段代码可以工作:
mysim=data.frame(x=rep(1:4,4),y=rbinom(16,10,0.5),id=rep(1:4,each=4))
my_colors<-c( ## add the standard plotly colors
'#1f77b4', #// muted blue
'#ff7f0e', #// safety orange
'#2ca02c', #// cooked asparagus green
'#d62728' #// brick red
)
plot_ly() %>%
add_trace(x=1:4,y=rbinom(4,10,0.4),type='scatter',mode='lines',
line=list(color='#CCCCCC',dash='dashed'),hoverinfo='skip',opacity=0.25) %>%
add_trace(data=mysim,x=~x,y=~y,type='scatter',mode='lines', split=~as.factor(id),
line=list(color=my_colors),hoverinfo='skip',opacity=1)
Run Code Online (Sandbox Code Playgroud)
遗憾的是我不再拥有那台机器了。plotly但从那时起似乎发生了一些变化。我还尝试使用color参数而split不是colors-listline来指定颜色。它没有任何影响。我仍然明白这个情节:
我在这里缺少什么?我怎样才能让它发挥作用?
我需要绘制具有连续误差带的数据。我想以与 相同的方式使用Plotly Expressplotly.express.scatter,但不是使用误差线来获得连续的误差带。对于“连续误差带”,我正在谈论这一点:
plotly ×10
python ×4
r ×4
plot ×2
colors ×1
d3.js ×1
errorbar ×1
html ×1
htmlwidgets ×1
javascript ×1
matplotlib ×1
pandas ×1
plotly-dash ×1
r-plotly ×1
reactjs ×1
statistics ×1
svg ×1