我正在使用绘图图绘制大量数据的比较。描述每一行的字符串往往会变长,所以我需要将它们设为多行。但是,对于许多情节,图例可能会从屏幕上消失。我想将图例分成两列。有没有办法在情节中做到这一点?看看help(plotly.graph_objs.Legend)没有像 matplotlib 那样的 ncol 或类似的论点,我在 plotly 文档中找不到任何对此的引用。
下面是一些示例代码:
import numpy as np
import matplotlib.cm as cm
py.sign_in("XXX", "XXXX")
N = 10
colors=['rgba(%f,%f,%f,%f)' % tuple(c) for c in cm.rainbow((np.linspace(0,1,N)),bytes=True)]
data = []
lab = 'Long<br>Multiline<br>string<br>describing %s'
for i in range(0,N):
x = np.linspace(0,np.random.uniform(5,10),10)
y = np.linspace(1,np.random.uniform(0,1),10)
label = lab % i
d = Scatter(
x=x,y=y,
mode='lines',
name=label,text=(label,)*len(x),
xaxis='x1',yaxis='y1',
line=Line( color=colors[i]) )
data.append(d)
py.iplot(data)
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 plotly 上制作带注释的热图。
import plotly.plotly as py
import plotly.tools as tls
from plotly.graph_objs import *
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('masterc.csv')
locations = {}
anno = []
for i in range(df.shape[0]):
locations.setdefault((df.iat[i,2],df.iat[i,6]),0)
locations[(df.iat[i,2],df.iat[i,6])]+=df.iat[i,8]
x1 = []
y1 = []
z1 = []
z1_text = []
for key in locations.keys():
if key[0] not in x1:
x1 += [key[0],]
if key[1] not in y1:
y1 += [key[1],]
for y in y1:
dummy = …Run Code Online (Sandbox Code Playgroud) 考虑以下 R 代码,以 plotly 生成等值线图:
#devtools::install_github("ropensci/plotly")
library(plotly)
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_world_gdp_with_codes.csv')
# light grey boundaries
l <- list(color = toRGB("grey"), width = 0.5)
# specify map projection/options
g <- list(
showframe = FALSE,
showcoastlines = FALSE,
projection = list(type = 'Mercator')
)
plot_ly(df, z = GDP..BILLIONS., text = COUNTRY, locations = CODE, type = 'choropleth',
color = GDP..BILLIONS., colors = 'Blues', marker = list(line = l),
colorbar = list(tickprefix = '$', title = 'GDP Billions US$'),
filename="r-docs/world-choropleth") %>%
layout(title = '2014 …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试绘制两组不同的数据,为我们正在处理的数据创建可视化。
本质上,一组数据将是河流的横截面(宽度、深度)。

另一组数据包括水位和记录这些水位的时间。(深度,时间)

我目前正在单独的图表中绘制每个图表,但需要使图表将水位数据覆盖到横截面数据上。这将需要多个 X 轴,因为范围不同。这在情节中可能吗?我在网上看到有人使用 Plotly 的数据编辑器的视频,但在使用他们的 API 方面没有发现太多。
另外,我知道一组数据以米为单位,另一组以英尺为单位——这些数据被用作示例,最终结果将以英尺为单位显示。
是否可以链接散点图的所有/部分点,因此每当您单击它们时,都会打开一个新选项卡并触发该点上链接的超链接?
我在 Django 网络服务器实现中使用 plotly,这意味着 plotly 是用 javascript 呈现的。
我找到了一个包含荷兰所有城市的GeoJSON 文件。我现在正在尝试使用 Plotly 绘制这张地图,但我似乎无法弄清楚如何做到这一点。我知道可以在特定国家/地区设置范围,但 Plotly 的默认地图似乎并不包含每个国家/地区的各个城市。
我正在基于这个 JSFiddle工作,我会在 Stackoverflow 的其他地方工作。我知道这些数据与荷兰无关,但目前这并不重要:我想要的只是一张看起来有点像这样的地图(但我喜欢在 Plotly 中进行,因为 Python 支持 Plotly)。
任何帮助是极大的赞赏!
Plotly.d3.csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_world_gdp_with_codes.csv', function(err, rows){
function unpack(rows, key) {
return rows.map(function(row) { return row[key]; });
}
var data = [{
type: 'choropleth',
locations: unpack(rows, 'CODE'),
z: unpack(rows, 'GDP (BILLIONS)'),
text: unpack(rows, 'COUNTRY'),
colorscale: [[0,'rgb(5, 10, 172)'],[0.35,'rgb(40, 60, 190)'],[0.5,'rgb(70, 100, 245)'], [0.6,'rgb(90, 120, 245)'],[0.7,'rgb(106, 137, 247)'],[1,'rgb(220, 220, 220)']],
autocolorscale: false,
reversescale: true,
marker: {
line: {
color: 'rgb(180,180,180)',
width: 0.5
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试根据这些绘图示例绘制3d表面图
当我在数据集上尝试这些示例时
test_plotly = structure(list(Age = c(82L, 82L, 83L, 83L, 83L, 81L,
81L,
81L, 79L, 80L, 82L, 78L, 78L, 79L, 78L, 80L, 79L, 77L, 77L, 77L,
77L, 78L, 76L, 77L, 77L, 78L, 77L, 76L, 83L, 79L, 76L, 84L, 75L,
75L, 77L, 74L, 74L, 75L, 74L, 74L, 73L, 73L, 74L, 81L, 84L, 73L,
72L, 73L, 71L, 71L, 73L, 72L, 79L, 72L, 71L, 76L, 72L, 75L, 73L,
71L, 70L, 79L, 69L, 70L, 70L, 70L, 77L, 69L, 69L, 68L, 69L, 73L, …Run Code Online (Sandbox Code Playgroud) 如何将图表标题左对齐plot_ly(从中创建ggplotly)?
library(ggplot2)
library(plotly)
p <-
ggplot(mtcars, aes(mpg, cyl)) +
geom_point() +
ggtitle("My Title") +
# Not necessary by default:
theme(plot.title = element_text(hjust = 0.0))
p
ggplotly(p)
Run Code Online (Sandbox Code Playgroud)
p(预期标题对齐)的输出:
ggplotly(p) (标题对齐未保留):
我正在尝试制作带有“时间标记”的图形。这些时间标记是某些日期的垂直线。时间数据是POSIXct格式。我想使用Plotly的出色交互界面,并在其中使用ggplot对象。
问题是在使用ggplotly()之后,这些“时间标记”没有显示出来。我已经尝试过了,plotly::add_segments()但是没有用。这是两个可复制的示例:
1.使用非POSIXct数据可以正常工作
Run Code Online (Sandbox Code Playgroud)# dummy dataset df2 = data.frame(id = 1:10, measure = runif(10, 0, 20)) events2 = data.frame(number = c(2,3,8)) # ggplot graph p2 = ggplot() + geom_line(data = df2, aes(x = id, y = measure)) + geom_vline(data = events2, aes(xintercept = events2$number), color = "red") p2 # plotly graph that displays the geom_vline properly ggplotly(p2)
2.使用POSIXct时,数据无法显示正确的结果
Run Code Online (Sandbox Code Playgroud)# dummy dataset df = data.frame(date = seq(as.POSIXct("2017-07-01", tz = "UTC", format = "%Y-%m-%d"), as.POSIXct("2018-04-15", tz = "UTC", format = …
plotly ×10
r ×4
javascript ×3
plot ×3
ggplot2 ×2
python ×2
3d ×1
annotations ×1
choropleth ×1
django ×1
geom-vline ×1
heatmap ×1
matplotlib ×1
plotly-dash ×1
posixct ×1
surface ×1