在plotly中使用add_trace,该跟踪用于我的特定图形 [英] add_trace in plotly, which trace to use for my particular graph

查看:332
本文介绍了在plotly中使用add_trace,该跟踪用于我的特定图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管我目前仍处于困境,但我正在努力使用R库在R中创建篮球投篮图.作为参考,我创建的图形类型希望在完成后看起来像这样:

I am working on creating basketball shot charts in R using the library plotly, although I am currently stuck. For reference, the type of graph I'm creating will hopefully look a bit like this when they're complete:

从绘图角度来看,我需要使用跟踪类型,该类型将允许我在整个图形上放置六边形(或其他形状).我相信我将能够适当地调整六边形的颜色和大小参数,以说明哪些六边形应为红色,橙色与黄色以及哪些六边形应为全尺寸,较小与不存在.完全没有.我只需要知道从跟踪/模式开始的地方.

From a plotly perspective, I need to use a trace type that will allow me to place hexagons (or some other shape) on the entire graph. I'm confident that I'll be able to appropriately tune the color and size parameters of the hexagons to account for which hexagons should be red vs. orange vs. yellow, and which hexagons should be full size vs. smaller vs. not present at all. I just need to know where to start with the trace / mode.

图形的下面是我在每次篮球投篮时具有x和y坐标的数据. (假设我在上面显示的图形对于两个轴都是0:50,并且我具有每个范围内的射击数据).

Underlying the graph is data I have with x and y coordinates for each basketball shot. (assume the graph I've displayed above is 0:50 for both axes, and that i have shot data for shots in each range).

提前道歉,这不是特定于代码/编程的问题,但请不要投票结束.任何对此的想法表示赞赏!

Apologies in advance that this is not a code/programming specific question, but please don't vote to close. Any thoughts on this are appreciated!

谢谢

编辑-热图可能是一个选项,但是看来plotly的热图轨迹没有可以设置为六边形的标记参数.

EDIT - heatmaps could be an option, but it does not appear that plotly's heatmap trace has a marker parameter that I could set to hexagon.

EDIT2-当然可以使用mode ='markers'的散点图,但是我担心带有〜2500个标记的图形会滞后(我的图形是47x50,我希望每个整数对都有一个标记)

EDIT2 - ofcourse scatter plot with mode='markers' is an option, but i am concerned that a graph with ~2500 markers will lag (my graph is 47x50, and I'd like each integer pair to have a marker).

推荐答案

您可以使用scatter图并将marker symbol设置为hexagon2.该字段的行可以创建为shapes.

You could use a scatter plot and setting the marker symbol to hexagon2. The lines for the field could be created as shapes.

一些概念证明代码:

library('plotly')

p <- plot_ly()
p <- add_trace(p, 
               type = 'scatter', 
               mode = 'markers',
               marker = list(symbol = 'hexagon2',
                             size=c(200, 100, 20)),
               x = c(0.15, 0.2, 0.3),
               y = c(0.2, 0.4, 0.5))
p <- add_trace(p, 
               type = 'scatter', 
               mode = 'markers',
               marker = list(symbol = 'hexagon2',
                             size=c(50, 50, 50, 50, 50)),
               x = c(0.4, 0.5, 0.6, 0.45, 0.55),
               y = c(0.8, 0.8, 0.8, 0.825, 0.825))

p <- layout(p, 
            xaxis = list(range = c(0, 1)),
            yaxis = list(range = c(0, 1)),
            shapes = list(list(type = 'circle',
                               xref='x0',
                               yref='y0',
                               x0 = 0.1,
                               y0 = 1.4,
                               x1 = 0.9,
                               y1 = 0.6))
)
p

这篇关于在plotly中使用add_trace,该跟踪用于我的特定图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆