我想在 3D 图中的两点之间画一条线。但是,由于文档中建议的某些原因,我无法使用plotly.express。https://plotly.com/python/3d-line-plots/
是否可以使用plotly.graph_objects模块在3D图中画一条线?如果是这样,怎么办?
我想向我的线图添加许多带有箭头的注释。但是,我不想手动添加它们(就像我在下面的代码中所做的那样)。这将是一项艰巨的工作,我宁愿直接从 df['text'] 列(或本列中的列表)添加注释。
import plotly.express as px
import pandas as pd
# assign data of lists.
data = {'x': [0, 1, 2, 3, 4, 5, 6, 7, 8],
'y': [0, 1, 3, 2, 4, 3, 4, 6, 5],
'text':["","","Annotation1","","Annotation2","","","",""]}
# Create DataFrame
df = pd.DataFrame(data)
fig = px.line(df, x='x', y='y', title='I want to add annotation with the tekst column in my dataframe (instead of manually)')
fig.add_annotation(x=2, y=3,
text="Annotation1 (added manual)",
showarrow=True,
arrowhead= 2)
fig.add_annotation(x=4, y=4,
text="Annotation2 (added manual)",
showarrow=True,
arrowhead= …Run Code Online (Sandbox Code Playgroud) 我有一个数据框A
date Cluster count Users
01/01/2021 ClusterA 10
01/01/2021 ClusterB 10
01/01/2021 ClusterB 9
02/01/2021 ClusterA 14
02/01/2021 ClusterB 10
02/01/2021 ClusterB 5
Run Code Online (Sandbox Code Playgroud)
我想可视化集群之间的用户迁移,为此,我首先生成以下 dataframeB :
date Source Target Value
02/01/2021 ClusterA ClusterA 8
02/01/2021 ClusterA ClusterB 2
02/01/2021 ClusterB ClusterB 8
02/01/2021 ClusterB ClusterA 2
02/01/2021 ClusterC ClusterA 4
02/01/2021 ClusterC ClusterC 5
Run Code Online (Sandbox Code Playgroud)
我画了桑基图:
import plotly.graph_objects as go
label = ["ClusterA01/01/2021","ClusterB01/01/2021","ClusterC01/01/2021","ClusterA02/01/2021","ClusterB02/01/2021","ClusterC02/01/2021"]
source = [0, 0, 1, 1, 2,2]
target = [3, 4, 3, 4, 3,5]
value = [8, 2, …Run Code Online (Sandbox Code Playgroud) 这个问题之前已经被问过,但由于没有reprex而没有得到答案,所以让我试一下。
假设我有两个跨越不同日期范围的数据集。我想使用滑块控制每个的可视化。以下 reprex 将直接在下面创建视觉效果。
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
#+ message = FALSE, warning = FALSE
library(plotly)
library(crosstalk)
library(dplyr)
#+
```
```{r}
df1 <- data.frame(d = seq.Date(from = as.Date("2020-01-01"), by = "months", length.out = 100), v = runif(100))
df2 <- data.frame(d = seq.Date(from = as.Date("2020-6-01"), by = "months", length.out = 20), other_v = runif(20))
both_df <- full_join(df1, df2, by = 'd')
both_df_sh <- both_df %>% SharedData$new(group = "boom")
selector <- filter_slider(id …Run Code Online (Sandbox Code Playgroud) 我想自定义当我将鼠标悬停在栏上时我在情节中看到的内容。
请查看帖子末尾的 reprex。我看了一下
https://community.rstudio.com/t/changing-hovertext-in-plotly/71736
但我一定犯了一些错误。我希望当我将鼠标悬停在栏上时只看到变量“macro_sector”和“amount”,而栏上根本没有静态文本。我怎样才能做到这一点?非常感谢
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(plotly)
#> Loading required package: ggplot2
#>
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#>
#> last_plot
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following object is masked from 'package:graphics':
#> …Run Code Online (Sandbox Code Playgroud) 我正在使用绘图来显示图像fig=px.imshow(img)
我希望它有一个类似于饼图或条形图中的离散图例:fig2 = px.pie(df, values=df[0],names=df.index,color =df.index, color_discrete_map= h.colormap)
imshow()没有争论color_discret_map,但也许可以有解决方法?
我知道用 matplotlib 是可能的,但我需要用绘图来做到这一点。
Plotly 在哪里存储节点的 X 和 Y 坐标(或 XY 坐标的 Plotly 等效项)?特别是当类型=“sankey”时。
例如:
library(plotly)
fig <- plot_ly(
type = "sankey",
orientation = "h",
node = list(
label = c("A1", "A2", "B1", "B2", "C1", "C2"),
color = c("blue", "blue", "blue", "blue", "blue", "blue"),
pad = 15,
thickness = 20,
line = list(
color = "black",
width = 0.5
)
),
link = list(
source = c(0,1,0,2,3,3),
target = c(2,3,3,4,4,5),
value = c(8,4,2,8,4,2)
)
)
fig <- fig %>% layout(
title = "Basic Sankey …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 R 网状包将绘图转换为静态图像。我正在使用 save_image/kaleido。
初始设置:
install.packages("reticulate")
reticulate::install_miniconda()
reticulate::conda_install('r-reticulate-test', 'python-kaleido')
reticulate::conda_install('r-reticulate-test', 'plotly', channel = 'plotly')
reticulate::use_miniconda('r-reticulate-test')
Run Code Online (Sandbox Code Playgroud)
这是我的(有缺陷的)尝试:
> library(plotly)
> p <- plot_ly(x = 1:10)
> save_image(p,"test.png")
No trace type specified:
Based on info supplied, a 'histogram' trace seems appropriate.
Read more about this trace type -> https://plotly.com/r/reference/#histogram
Error in py_run_string_impl(code, local, convert) :
NameError: name 'sys' is not defined
>
Run Code Online (Sandbox Code Playgroud)
我的查询是:如何修复名称“sys”未定义的错误?
有趣的是,如果我这样做:
> reticulate::repl_python()
Python 3.10.6 (/root/.local/share/r-miniconda/envs/r-reticulate-test/bin/python)
Reticulate 1.26.9000 REPL -- A Python interpreter in R. …Run Code Online (Sandbox Code Playgroud) 我在这里找到了这篇 stackoverflow 帖子(在浏览器中突出显示/查找散点图中的数据点),其中展示了如何为散点图中的散点图创建搜索栏。
我尝试运行此示例中提供的代码:
library(plotly)
library(htmlwidgets)
library(htmltools)
pcaCars <- princomp(mtcars, cor = TRUE)
carsHC <- hclust(dist(pcaCars$scores), method = "ward.D2")
carsDf <- data.frame(pcaCars$scores, "cluster" = factor(carsClusters))
carsClusters <- cutree(carsHC, k = 3)
carsDf <- transform(carsDf, cluster_name = paste("Cluster", carsClusters))
p <- plot_ly(carsDf, x = ~Comp.1 , y = ~Comp.2, text = rownames(carsDf),
mode = "markers", color = ~cluster_name, marker = list(size = 11), type = 'scatter', mode = 'markers')
p <- htmlwidgets::appendContent(p, htmltools::tags$input(id='inputText', value='Merc', ''), htmltools::tags$button(id='buttonSearch', 'Search'))
p <- …Run Code Online (Sandbox Code Playgroud) plotly ×10
python ×5
r ×5
r-plotly ×2
annotations ×1
crosstalk ×1
imshow ×1
javascript ×1
label ×1
pandas ×1
plot ×1
reticulate ×1