标签: plotly

情节设置颜色

我觉得我尝试了一切,但似乎没有任何效果:

            var charData = [{
                    x: x1,
                    y: y,
                    type: 'bar',
                    color: 'rgb(31,119,180)',
                    orientation: 'h',
                    name: 'Nuværende',
                    bar: {
                        color: 'rgb(rgb(31, 114, 225)'
                    }
                }, {
                    x: x2,
                    y: y,
                    type: 'bar',
                    orientation: 'h',
                    name: 'Forventet'
                }],
                layout = {
                    title: 'Brugere',
                    barmode: 'stack',
                    legend: {
                        orientation: 'h'

                    }
                };
            Plotly.newPlot(area,charData,layout);
Run Code Online (Sandbox Code Playgroud)

我也试过:

            var charData = [{
                    x: x1,
                    y: y,
                    type: 'bar',
                    color: 'rgb(31,119,180)',
                    orientation: 'h',
                    name: 'Nuværende',
                    color: '#23b7e5'
                }, {
                    x: x2,
                    y: y,
                    type: 'bar',
                    orientation: 'h', …
Run Code Online (Sandbox Code Playgroud)

javascript plotly

2
推荐指数
1
解决办法
6313
查看次数

Plotly R 中的分组线图:如何控制线条颜色?

我有一堆来自同一主题的研究的“配对”观察结果,我正在尝试构建一个意大利面条图来可视化这些观察结果,如下所示:

library(plotly)
df <- data.frame(id = rep(1:10, 2),
                 type = c(rep('a', 10), rep('b', 10)),
                 state = rep(c(0, 1), 10),
                 values = c(rnorm(10, 2, 0.5), rnorm(10, -2, 0.5)))
df <- df[order(df$id), ]
plot_ly(df, x = type, y = values, group = id, type = 'line') %>%
  layout(showlegend = FALSE)
Run Code Online (Sandbox Code Playgroud)

它产生了我正在寻找的正确情节。但是,代码以自己的颜色显示了每个分组的行,这真的很烦人,让人分心。我似乎无法找到摆脱颜色的方法。

额外问题:我实际上想使用color = state该变量并实际为斜线着色。

任何方法/想法?

r plotly

2
推荐指数
1
解决办法
8699
查看次数

增加绘图图形标题的大小

我正在使用plotly 4.5.2.

这是我如何使用titlefont=list(size=30)in更改绘图标题的大小layout():

library(plotly)
x <- 0:10
y <- 0:10
dd <- transform(expand.grid(x=x, y=y), z=x+y)
dd1 <- data.frame(x=x, y=y) 
pp <- plot_ly() %>% 
  layout(title="Hello", titlefont=list(size=30)) %>%
  add_trace(data=dd, x=~x, y=~y, z=~z, type="heatmap") %>% 
  add_trace(data=dd1, x=~x, y=~y, type="scatter", mode="lines", showlegend=FALSE)
Run Code Online (Sandbox Code Playgroud)

但是当标题太大时无法正确呈现:

在此处输入图片说明

这是一个错误,还是我做错了什么?

r plotly

2
推荐指数
1
解决办法
3505
查看次数

将 onclick 打开超链接事件添加到在 R 中创建的 html 小部件

我希望能够做类似这个答案的事情,但不使用闪亮的。我还想绑定打开与数据点关联的超链接的 onclick 事件。

我正在使用saveWidget函数 fromhtmlwidgets并且知道我可以使用 包中的appendContent函数插入 javascript 代码htmltools。

这是一个小示例代码:

library(ggplot2)
library(plotly)
library(htmlwidgets)
library(htmltools)

path.test.results <- "C:\\Users\\img\\"

myData <- data.frame(x=c(1,2,3), y=c(3,2,1))
myLinks <- c("https://www.google.com/", "https://stackoverflow.com/", "https://www.r-project.org/")

ggp <- ggplot(data=myData, aes(x=x, y=y)) + geom_point()
ply <- plotly_build(ggp)

ply$elementId <- "PlotlyGraph"

#javascript <- HTML('<script>document.getElementById("htmlwidget_container").innerHTML = "test";</script>')
javascript <- HTML(paste(
        paste('<button type="button" onclick="document.getElementById(',"'", 'PlotlyGraph', "'", ').style.display=',
                "'", 'none', "'", '">Hide Plot</button>', sep=''),
        paste('<button type="button" onclick="document.getElementById(',"'", 'PlotlyGraph', "'", ').style.display=',
                "'", 'block', "'", '">Show …
Run Code Online (Sandbox Code Playgroud)

javascript r hyperlink plotly htmlwidgets

2
推荐指数
1
解决办法
1534
查看次数

如何在绘图中为形状添加名称或标签?

我创建了一个简单的绘图折线图,如下所示:

var trace1 = {
x: [1, 2, 3, 4],
y: [10, 15, 13, 17],
type: 'scatter' 
};

var layout = {
xaxis:{
title:"x-axis",
tickangle:45,
rangemode:'nonnegative',
autorange:true,
exponentformat: "none"
},
yaxis:{
title: "Time",
tickangle:45,
rangemode:'nonnegative',
range:[0,20],
autorange: false
},
shapes: [
    {
    type: 'line',
    xref: 'paper',
    x0: 0,
    y0: threshold1,
    x1: 1,
    y1: threshold1,
    line:{
        color: 'rgb(255, 0, 0)',
        width: 2,
        dash:'dot'
        },
    },
    {
    type: 'line',
    xref: 'paper',
    x0: 0,
    y0: threshold2,
    x1: 1,
    y1: threshold2,
    line:{
        color: 'rgb(0, …
Run Code Online (Sandbox Code Playgroud)

javascript plotly

2
推荐指数
1
解决办法
8609
查看次数

绘图不显示轴标签或标题

我有一个 Python 项目,它使用plotly. 这是我的代码:

def PlotData(data):
    trace1 = go.Scatter(
        y=PriceData,
        name="Prices",
        mode="lines+markers"
    )
    trace2 = go.Scatter(
        y=MarketData,
        name="Market Price",
        mode="lines+markers"
    )
    data = [trace1, trace2]
    layout = go.Layout(
        title='Plot Title',
        xaxis=dict(
            title='x Axis',
            titlefont=dict(
                family='Courier New, monospace',
                size=18,
                color='#7f7f7f'
            )
        ),
        yaxis=dict(
            title='y Axis',
            titlefont=dict(
                family='Courier New, monospace',
                size=18,
                color='#7f7f7f'
            )
        )
    )
    go.Figure(data=data, layout=layout)
    plotly.offline.plot(data)
Run Code Online (Sandbox Code Playgroud)

在layout我得到的结果图表没有标题或标签不工作。我该如何解决?

python plotly

2
推荐指数
1
解决办法
6235
查看次数

在 R Shiny 中的绘图顶部显示 X 轴而不是底部?

如何在 Plotly 水平条形图的顶部而不是底部显示 x 轴?在顶部和底部显示 x 轴也可以。该图将显示在 R Shiny 中,并且必须是 Plotly 而不是 ggplotly。谢谢!

来自https://plot.ly/r/horizo​​ntal-bar-charts/ 的示例:

library(plotly)
plot_ly(x = c(20, 14, 23), 
y = c('giraffes', 'orangutans', 'monkeys'), 
type = 'bar', 
orientation = 'h')
Run Code Online (Sandbox Code Playgroud)

编辑:HubertL 提供了一个解决方案(谢谢!),将 x 轴放在顶部,但随后与图表标题重叠。我没有指定我正在使用标题的错。有没有办法让 x 轴标题和 x 轴刻度不与情节标题重叠?

plot_ly(x = c(20, 14, 23), 
        y = c('giraffes', 'orangutans', 'monkeys'), 
        type = 'bar', 
        orientation = 'h') %>%
   layout(xaxis = list(side ="top", 
          title = "EXAMPLE X AXIS TITLE"), 
          title = "EXAMPLE PLOT TITLE")
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

r shiny plotly

2
推荐指数
1
解决办法
3125
查看次数

情节 - 表面 - 文字悬停信息不起作用

我已经用 plotly 构建了一个表面图,我正在尝试根据我自己的文本来设置 hoverinfo。奇怪的是它不再起作用了。

library(plotly)
x <- rnorm(10)
y <- rnorm(10)
z <- outer(y, x)

p <- plot_ly(x = ~x, y = ~y, z = ~z, type = "surface",
             text = ~paste0("My X = ", x, "\n My Y = ", y, "\n My Z = ", z),
             hoverinfo = "text") %>% layout(dragmode = "turntable")
print(p)
Run Code Online (Sandbox Code Playgroud)

虽然

p <- plot_ly(x = ~x, y = ~y, z = ~z, type = "surface") %>% layout(dragmode = "turntable")
Run Code Online (Sandbox Code Playgroud)

效果很好。

我也试过用\nby代替<br …

r plotly

2
推荐指数
1
解决办法
1091
查看次数

r plotly 如何使用纬度、经度和 z 获得 3d 表面

我有大约 10 个位置的纬度、经度和数据值。这是我可以轻松为我的问题构建的数据框示例

x <- c("-108.6125","-108.5114","-108.805","-108.4014","-108.5615","-108.8349","-108.225","-108.3139","-108.5568","-108.4968")
y <- c("39.02205","39.22255","39.598","38.89478","39.06429","39.27625","39.03","39.1306","39.14823","38.89795")
z <- c("60.7735","56.45783","49.65","60.15","50","53.95417","50.825","56","55.843","38.73333")
df <- data.frame(x = as.numeric(x),y = as.numeric(y),z = as.numeric(z))
Run Code Online (Sandbox Code Playgroud)

我想根据数据框中的 x、y 和 z 值创建一个 3d 表面。x 和 y 是纬度和经度。z 是经纬度对的值。

我可以做一个 3d 散点图,plot_ly(df, x = ~x, y = ~y, z = ~z) %>% add_markers(color = ~z)但向此代码添加 add_surface 不起作用。

涉及火山 df ( plot_ly() %>% add_surface(x = ~x, y = ~y, z = ~volcano)的绘图 3d 表面示例使用均匀分布的 x 和 y 值,z 是一个二维数组。如果我理解正确,我需要每个位置的 x 和 y 对。

是否可以进行某种操作来创建 add_surface …

3d r plotly

2
推荐指数
1
解决办法
1274
查看次数

精心给出错误消息“ TypeError:__init __()得到了意外的关键字参数'encoding'”-Python

我昨天才碰到Plotly,我试图找到一种很好的方式来生成表格,类似于在Matplotlib中生成图表。

最初,我尝试使用自己的数据,并始终在标题中得到错误消息。因此,我已经从可打印的网站复制并粘贴了准确的代码,仍然出现此错误。有人遇到过吗?有没有人有办法解决吗。我觉得这不是我的代码的简单问题。

import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_usa_states.csv')

trace = go.Table(
    header=dict(values=list(df.columns),
                fill = dict(color='#C2D4FF'),
                align = ['left'] * 5),
    cells=dict(values=[df.Rank, df.State, df.Postal, df.Population],
               fill = dict(color='#F5F8FF'),
               align = ['left'] * 5))

data = [trace]
py.iplot(data, filename = 'pandas_table')
Run Code Online (Sandbox Code Playgroud)

这是我使用的代码,导致以下错误:

TypeError: __init__() got an unexpected keyword argument 'encoding'

如果有人可以替代plotly,那么在这里我可以制作美观的表,这也将非常有帮助。

非常感谢

python pandas plotly plotly-python

2
推荐指数
1
解决办法
1907
查看次数

标签 统计

plotly ×10

r ×6

javascript ×3

python ×2

3d ×1

htmlwidgets ×1

hyperlink ×1

pandas ×1

plotly-python ×1

shiny ×1