简体   繁体   English

绘制3d和2d子图

[英]3d and 2d subplots in plotly

I'm trying to produce 3d and 2d subplots on plotly. 我正在尝试以绘图方式生成3d和2d子图。 In a simple test case, I generate two subplots, where the first has two wireframe plots, and the second has a heatmap characterizing the difference between the two 3d plots. 在一个简单的测试用例中,我生成了两个子图,第一个子图具有两个线框图,第二个子图具有表征两个3d图之间差异的热图。

When I attempt to plot either the first (3d) or the second (2d) subplot without the other one, they display correctly. 当我尝试绘制第一个(3d)或第二个(2d)子图而没有另一个图时,它们将正确显示。 But when I attempt to plot both subplots, I get the following error (offline mode in ipython): 但是,当我尝试绘制两个子图时,出现以下错误(ipython中的离线模式):

Javascript error adding output!
TypeError: Cannot read property 'overlaying' of undefined
See your browser Javascript console for more details.

Here is the code I used to generate the plots: 这是我用于生成图的代码:

#! /usr/bin/env python

from plotly import tools 
import plotly.plotly as py
import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
import numpy as np

init_notebook_mode()

# Creating the data
x = np.linspace(-5, 5, 50)
y = np.linspace(-5, 5, 50)
xGrid, yGrid = np.meshgrid(y, x)
R = np.sqrt(xGrid ** 2 + yGrid ** 2)
z = np.sin(R)
z2 = np.cos(R)

line_marker = dict(color='#0066FF', width=2)
line_marker2 = dict(color='green', width=2)

scene=dict(
 xaxis=dict(
     gridcolor='rgb(255, 255, 255)',
     zerolinecolor='rgb(255, 255, 255)',
     showbackground=True,
     backgroundcolor='rgb(230, 230,230)'
 ),  
 yaxis=dict(
     gridcolor='rgb(255, 255, 255)',
     zerolinecolor='rgb(255, 255, 255)',
     showbackground=True,
     backgroundcolor='rgb(230, 230,230)'
 ),  
 zaxis=dict(
     gridcolor='rgb(255, 255, 255)',
     zerolinecolor='rgb(255, 255, 255)',
     showbackground=True,
     backgroundcolor='rgb(230, 230,230)'
 )
)

fig = tools.make_subplots(rows=1,cols=2,specs=[[{'is_3d':True},{'is_3d':False}]])
#comment this out and subplot 2 works
for i, j, k in zip(xGrid, yGrid, z): 
    fig.append_trace(go.Scatter3d(x=i, y=j, z=k, mode='lines', line=line_marker,name='wire1'),1,1) 
for i, j, k in zip(xGrid, yGrid, z2): 
    fig.append_trace(go.Scatter3d(x=i, y=j, z=k, mode='lines', line=line_marker2,name='wire2'),1,1)

#comment this out and subplot 1 works
fig.append_trace(go.Heatmap(x=x, y=y, z=np.sqrt((z-z2)**2)),1,2) 
fig['layout'].update(title='3d with heatmap',height=600,width=1000,showlegend=False)
plot_url = iplot(fig)

Second question: 第二个问题:

Assuming this can be handled, is there any way to have both subplots respond to hovermouse actions? 假设可以解决,是否有任何办法让两个子图都对悬停鼠标的动作做出响应? (eg mouse hovering over some space in xy on the 3d plot also highlights the corresponding box on the heatmap?) (例如,将鼠标悬停在3d图上xy的某个空间上还会在热图上突出显示相应的框吗?)

This is now possible: https://plot.ly/python/mixed-subplots/ . 现在这是可能的: https : //plot.ly/python/mixed-subplots/ From their example: 从他们的例子:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM