我正在尝试更改折线图中特定点的颜色。我发现您可以使用以下代码片段更改迹线的颜色:
var update = {
marker: {
color: 'orange',
size: 10
}
};
Plotly.restyle('myDiv', update);
Run Code Online (Sandbox Code Playgroud)
我还发现可以通过以下方式更改第一个点的颜色:
Plotly.restyle('myDiv', 'marker.color', [['red']]);
Run Code Online (Sandbox Code Playgroud)
但我不明白如果我只知道特定点的 x,y 坐标,我如何能够改变它的颜色。
链接到 Codepen
我正在研究华丽而强大的 Plotly Python API,其目标是生成静态 html 仪表板。
这提出了两个问题:
为了生成 html,我看到以下示例。图表似乎是通过 URL 嵌入的。自从plotly 开源以来,这个 URL 嵌入实现仍然适用吗?现在有其他方法可以将绘图发送到静态 html 吗?
如何控制绘图/仪表板元素的布局?例如,在 Bokeh 中,我们可以执行以下操作:
bar = Bar(<define bar plot>)
line = Line(<define line plot>)
donut = Donut(<define donut chart>)
bar_line_panel = hplot(bar, line)
final_layout = vplot(bar_line_panel, donut)
output_file('foo.html')
show(final_layout)
渲染的 html 文件将包含圆环图上方彼此相邻的折线图和条形图。plotly 中是否有类似的功能,或者是否需要模板和 html/css 争论来指定绘图元素的布局,如本例所示?
感谢您抽出时间,非常期待在 Plotly 中创建一些交互式可视化!
我希望以下应用程序中的 3 个圆环图在其 div 内居中,但它们都是右对齐的。当更改浏览器窗口(macOS 上的 Safari)的宽度时,它们会按照我希望的方式居中,但在页面最初加载时不会居中。
有什么想法如何使这 3 个图表始终位于其下方显示的标题上方的中心吗?
library(shiny)
library(plotly)
# Define UI for application
ui <- navbarPage("Home",
tabPanel("Tab1",
tags$style(type="text/css",
"h3 { text-align:center; }"
),
fluidRow(
column(4,
h2(plotlyOutput("plot1", height = "100%")),
h3("Score")
),
column(4,
h2(plotlyOutput("plot2", height = "100%")),
h3("Score")
),
column(4,
h2(plotlyOutput("plot3", height = "100%")),
h3("Score")
)
)
)
)
# Define server logic
server <- function(input, output) {
output$plot1 <- renderPlotly({
iScore <- sample(70:100, 1)
plot_ly(width = 150, height = 150,
marker = list(colors = c("#65b146", "rgba(0,0,0,0)"))) …Run Code Online (Sandbox Code Playgroud) 我正在学习如何使用他们的示例和我自己的数据在 Plotly 上绘制 3D 散点图。样品在这里
我可以绘制散点图(它看起来很酷),但我无法让不同的数据系列点显示为单独的颜色。
import plotly #load plotly for plotting
import plotly.plotly as py
from plotly import tools
from plotly.graph_objs import * #all the types of plots that we will plot here
plotly.offline.init_notebook_mode() # run at the start of every ipython notebook
trace1 = Scatter3d(
x = res,
y = lc,
z = spent,
mode='markers',
marker=dict(
size=12,
color=["z","y","x"], # set color to an array/list of desired values
colorscale='Viridis', # choose a colorscale
opacity=0.8
)
) …Run Code Online (Sandbox Code Playgroud) 就像下面给出的代码一样,我们可以在plotly.js中分别手动设置X轴和Y轴的日期和时间吗?
var layout = {
xaxis: {range: [2, 5]},
yaxis: {range: [2, 5]}
};
var layout = {
xaxis: {range: ["2017-04-04", "2017-08-06"]},
yaxis: {range: ["9:00:00", "24:00:00"]}
};
Run Code Online (Sandbox Code Playgroud) 是否可以将plotly/ggplotly图导出到Powerpoint并保持其交互性?我的意思是,例如允许用户更改绘图线的颜色、粗细等。
示例代码:
set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]
p <- ggplot(data = d, aes(x = carat, y = price)) +
geom_point(aes(text = paste("Clarity:", clarity))) +
geom_smooth(aes(colour = cut, fill = cut)) + facet_wrap(~ cut)
gg <- ggplotly(p)
Run Code Online (Sandbox Code Playgroud)
顺便说一句,使用webshot包将绘图导出为.png文件不是解决方案。我应该能够编写这个解决方案,并从 R 或任何其他编程语言自动化 - 在线工具或任何其他应用程序,用户应该单击它来获取结果,但不能解决问题。
它有一个简单的示例,说明如何:
我已经为绘图生成了 json 文件 (p1):
json<-plotly_json(p1,FALSE)
write(json,'test.json')
Run Code Online (Sandbox Code Playgroud)
但我无法在简单的 html/java 脚本测试中生成绘图。我已经能够在 html/javascipt 中生成绘图,而不是从 R 保存的 json 文件生成绘图。这看起来很简单,但我是 html 新手,显然缺少一些明显的东西。
我想删除子图的边距:tools.make_subplots(请参阅代码图 g01)。horizontal_spacing或者vertical_spacing没有帮助。
对于正常的绘图,我可以使用 go.Margin(l=0, r=0 ..) 来完成此操作。(参见代码中的图 g11)。
我只希望子图有相同的行为。有人有什么想法吗?
import dash
from dash.dependencies import Output, Event
import dash_core_components as dcc
import dash_html_components as html
import base64
from plotly import tools
import plotly.plotly as py
import plotly.graph_objs as go
from collections import deque
import numpy as np
import random
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Graph(id='g01',),
dcc.Interval(id='graph-update', interval= 1000 * 1),
dcc.Graph(id='g11',),
dcc.Interval(id='graph-update', interval= 1000 * 1),
], style={
'margin-left' : '0',
'margin-right' : '0',
'padding-left' : …Run Code Online (Sandbox Code Playgroud) 我正在尝试将节点标签的方向更改为节点左侧和空白区域中,以获得更好的可读性,类似于“C”标签的对齐方式。
import plotly.graph_objects as go
fig = go.Figure(data=[go.Sankey(
node = dict(
pad = 15,
thickness = 20,
line = dict(color = "black", width = 0.5),
label = ["A1", "A2", "B1", "B2", "C1", "C2"],
color = "blue"
),
link = dict(
source = [0, 1, 0, 2, 3, 3], # indices correspond to labels, eg A1, A2, A2, B1, ...
target = [2, 3, 3, 4, 4, 5],
value = [8, 4, 2, 8, 4, 2]
))])
fig.update_layout(title_text="Basic Sankey Diagram", font_size=10) …Run Code Online (Sandbox Code Playgroud) 我想放大使用 的绘图上的 y 轴rangeslider。
一个可重现的例子:
library(ggplot2)
library(plotly)
p <- ggplot(faithful, aes(x = waiting)) +
geom_histogram(bins = 30)
p <- ggplotly(p)
p <- rangeslider(p)
p
Run Code Online (Sandbox Code Playgroud)
我可以缩放的方式如下:

但是,我希望也能够像这样缩放(这是通过不添加 来完成的rangeslider):

我认为这可以通过使用类似的东西来完成
p <- layout(p, dragmode = "zoom")
Run Code Online (Sandbox Code Playgroud)
但我没能完成这项工作。
plotly ×10
r ×4
javascript ×3
ggplotly ×2
plot ×2
python ×2
python-3.x ×2
date ×1
ggplot2 ×1
json ×1
plotly-dash ×1
powerpoint ×1
r-plotly ×1
shiny ×1
time ×1