情节:如何向现有情节添加箭袋? [英] Plotly: How to add quivers to an existing plot?

查看:48
本文介绍了情节:如何向现有情节添加箭袋?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 plotly (python) 向现有图形添加箭袋.但我能找到的唯一和平的文档要么只创建一个箭袋(

完整代码:

import plotly.figure_factory as ff将 numpy 导入为 npx,y = np.meshgrid(np.arange(0, 2, .2), np.arange(0, 2, .2))u = np.cos(x)*yv = np.sin(x)*yfig1 = ff.create_quiver(x, y, u, v)fig2 = ff.create_quiver(x, y, u*0.9, v*2)fig1.add_traces(data = fig2.data)图1.show()

I'd like to add quivers to an existing figure with plotly (python). But the only peace of documentation I could find either create only one quiver (here) or a brand new figure (there).

Here's the example on plotly doc :

import plotly.figure_factory as ff

import numpy as np

x,y = np.meshgrid(np.arange(0, 2, .2), np.arange(0, 2, .2))
u = np.cos(x)*y
v = np.sin(x)*y

fig = ff.create_quiver(x, y, u, v)
fig.show()

If anyone has a better understanding of plotly that I do, I'd appreciate a lot a few explanations!

Thanks a lot,

解决方案

Assuming that you'd like to add quivers to an existing ff.create_quiver() figure, all you have to do is:

  1. Create fig1 = ff.create_quiver(x, y, u, v),
  2. create another figure with other attributes fig2 = ff.create_quiver(x, y, u*0.9, v*2),
  3. and add the resulting fig2.data to fig1 using fig1.add_traces(data = fig2.data)

Plot:

Complete code:

import plotly.figure_factory as ff
import numpy as np

x,y = np.meshgrid(np.arange(0, 2, .2), np.arange(0, 2, .2))
u = np.cos(x)*y
v = np.sin(x)*y

fig1 = ff.create_quiver(x, y, u, v)

fig2 = ff.create_quiver(x, y, u*0.9, v*2)
fig1.add_traces(data = fig2.data)
fig1.show()

这篇关于情节:如何向现有情节添加箭袋?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆