我有一个数据框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 是可能的,但我需要用绘图来做到这一点。
我正在尝试使用 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) 我创建了一个函数来在 Plotly 中创建一个带有 N 个子图的图形。为了隐藏这些子图的 x 轴标签,我想在这个函数内执行,例如 N=5
relayout!(p, xaxis_showticklabels=false)
relayout!(p, xaxis2_showticklabels=false)
relayout!(p, xaxis3_showticklabels=false)
relayout!(p, xaxis4_showticklabels=false)
Run Code Online (Sandbox Code Playgroud)
由于我事先不知道子图的数量 N,因此我想在循环中执行此操作,在命令 ...xaxis n _...中使用 for 循环计数器n 。
我尝试构造字符串,然后使用 eval(Meta.parse(expr)) 解析它,但这不起作用,因为 eval 仅在全局范围内有效。
任何有关如何执行此操作的建议将不胜感激。
我正在尝试从 导出矢量化图像plotly,但我想知道为什么.svg导出不保留文本字体。我的想法是导出.svg,在 Inkscape 中组织一些图像,然后将复杂图像导出为.png,但我需要与我的 Overleaf LaTeX 文档具有相同字体的图像。这是重现该问题的代码:
a = [1, 2, 3, 4, 5, 6]
b = [5, 6, 8, 2, 4, 3]
data = np.column_stack([a, b])
df = pd.DataFrame(data, columns=["A", "B"])
fig = px.scatter(df)
fig.update_layout(
font=dict(family="Computer Modern", size=25),
)
fig.write_image('png.png')
fig.write_image('svg.svg')
Run Code Online (Sandbox Code Playgroud)
我正在尝试在 Plotly 图的标题和标签中获取乳胶符号。我正在使用 VSCode,并在交互式窗口中运行代码。从我在其他帖子中看到的来看,Latex 在 Jupyter Notebook 中的使用看起来非常简单,但我无法让它在这个环境中工作。
我的环境:
蟒蛇3.10.4
情节5.9.0
vscode 1.62.3
我尝试过的:
这个基本代码片段应该可以根据我见过的大多数帖子工作,但不会在交互窗口中进行 Latex 渲染。它取自https://plotly.com/python/LaTeX/,一切看起来都很简单。这就是为什么我猜测这个问题与 VSCode 有关。
import plotly.graph_objs as go
fig = go.Figure()
fig.add_trace(go.Scatter(
x=[1, 2, 3, 4],
y=[1, 4, 9, 16],
name=r'$\alpha_{1c} = 352 \pm 11 \text{ km s}^{-1}$'
))
fig.add_trace(go.Scatter(
x=[1, 2, 3, 4],
y=[0.5, 2, 4.5, 8],
name=r'$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$'
))
fig.update_layout(
xaxis_title=r'$\sqrt{(n_\text{c}(t|{T_\text{early}}))}$',
yaxis_title=r'$d, r …Run Code Online (Sandbox Code Playgroud) 我正在尝试将此答案移植到 100% Plotly.JS 解决方案。TL;DR:如何使用 Plotly.JS(无 Python)在每个顶部有两个带有不透明度滑块的热图?
解决方案的开始,但如何添加第二条迹线?
const z = [];
for (let i = 0; i < 500; i++)
z.push(Array.from({ length: 600 }, () => Math.floor(Math.random() * 100)));
const data = [{ z: z, colorscale: "YlGnBu", type: "heatmap" }];
const steps = [];
for (let i = 0; i <= 100; i++)
steps.push({ label: i + "%", execute: true, method: "restyle", args: [{ opacity: i / 100 }] });
const layout = { sliders: [{ name: "slider", …Run Code Online (Sandbox Code Playgroud)我试图使用 ggplotly 函数来交互地使用 buraR 包中的trace_explorer 函数创建一个绘图,但生成的绘图不是预期的。
\n这是代码:
\nlibrary(ggplot2)\nlibrary(bupaR)\n\npatients <- eventdataR::patients # dataset from bupaR\n\ndf <- eventlog(patients,\n case_id = "patient",\n activity_id = "handling",\n activity_instance_id = "handling_id",\n lifecycle_id = "registration_type",\n timestamp = "time",\n resource_id = "employee")\n\n\n\n\ntr <- df %>% processmapR::trace_explorer(type = "frequent", coverage = 1.0)\n\n# tr # print the ggplot to see the expected output!\nggplotly(tr)\nRun Code Online (Sandbox Code Playgroud)\n和结果图
\n\n我尝试使用 ggplot2 中的主题选项,然后使用布局函数,但结果仍然相同,没有图例。
\nggtrace <- trace_explorer(df,\n type = "frequent", \n coverage = 1.0)\n\nggtrace <- ggtrace + \n theme (legend.position="none") +\n …Run Code Online (Sandbox Code Playgroud)