我尝试了几个小时,但没有成功。我的数据框很简单
df <- as.data.frame(matrix(c("g","d","a","b","z",5,4,3,2,1),5,2))
library("plotly")
p <- plot_ly(data = df,x = ~V1,y = ~V2,type = "scatter",mode = "lines+markers") %>%
layout(title = "my title")
p
Run Code Online (Sandbox Code Playgroud)
所以,这给我
但我不希望 x 轴按字母顺序排序,我只想保持原样并看到递减的图表。
我用 plotly 生成交互式绘图,并将它们保存为 html 页面。我是 ioslides 和 Rmarkdown 的新手,所以我通过互联网搜索,并没有找到解决方案。我想在我的幻灯片中包含一个带有 .html 扩展名的绘图图。所以我试过:
---
title: "Advanced Physics Project"
author: "mcandar"
output:
ioslides_presentation:
widescreen: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Introduction

Run Code Online (Sandbox Code Playgroud)
它不起作用。我想要的是一个嵌入了我的 html 图形的幻灯片,它的交互功能应该可以正常工作。是否可以?
我想尽可能加快余弦距离的计算scipy.spatial.distance.cosine
,所以我尝试使用numpy
def alt_cosine(x,y):
return 1 - np.inner(x,y)/np.sqrt(np.dot(x,x)*np.dot(y,y))
Run Code Online (Sandbox Code Playgroud)
我试过cython
from libc.math cimport sqrt
def alt_cosine_2(x,y):
return 1 - np.inner(x,y)/sqrt(np.dot(x,x)*np.dot(y,y))
Run Code Online (Sandbox Code Playgroud)
并逐渐得到改进(测试长度为50的numpy数组)
>>> cosine() # ... make some timings
5.27526156300155e-05 # mean calculation time for one loop
>>> alt_cosine()
9.913400815003115e-06
>>> alt_cosine_2()
7.0269494536660205e-06
Run Code Online (Sandbox Code Playgroud)
最快的方法是什么?不幸的是,我无法指定变量类型alt_cosine_2
,我将使用带有类型的numpy数组的此函数np.float32
plotly ×2
r ×2
cython ×1
html ×1
ioslides ×1
javascript ×1
numpy ×1
python ×1
r-markdown ×1
rstudio ×1
trigonometry ×1