首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >利用 python+plotly 制作Contour Plots模拟双波源干涉现象

利用 python+plotly 制作Contour Plots模拟双波源干涉现象

作者头像
FunTester
发布2019-10-17 02:52:27
5400
发布2019-10-17 02:52:27
举报
文章被收录于专栏:FunTesterFunTester

本人在学习使用 plotly 的contour plots 制作的时候,发现利用这个表格制作波的干涉模拟方面有很不错的效果,因为之前被各种波动方程和振动方程教育了很久,所以就用波函数来开动,下面分享代码,供大家参考。(我用 java 写的代码模拟的波函数的测试数据)

下面是 plotly 的全部代码,里面包含了两种生成 contour plots 图表的方式,一个生成的是单个图表,但是带着等高线,所以被我放弃了。另外一个生成是图表矩阵,我选的row=1,cols=1的模式。

 1#!/usr/bin/python
 2# coding=utf-8
 3
 4import plotly.plotly
 5from plotly.graph_objs import *
 6import plotly.graph_objs as go
 7import plotly.tools as tool
 8
 9z = []
10with open("/Users/Vicky/Documents/workspace/fission/long/intervene.log") as apidata:
11    for i in apidata:
12        data = i.split("\n")[0].split(",")
13        z.append(data)
14'''
15#这是单独一个表格的情况,但没找到去掉等高线的方法
16data = Data([
17    Contour(
18        z=z,
19        contours = dict(
20            coloring="heatmap"
21        )
22    )
23])
24plotly.offline.plot(data,filename="3333.html")
25'''
26data = {
27    'z': z,
28    'connectgaps': True,
29    'type': 'heatmap',
30    'zsmooth': 'best',
31    'showscale': True
32}
33fig = tool.make_subplots(rows=1, cols=1)
34fig.append_trace(data, 1, 1)
35plotly.offline.plot(fig,filename= "3333.html")

下面是 java 生成数据的代码:

 1package practise;
 2
 3import java.awt.Point;
 4import java.util.ArrayList;
 5import java.util.List;
 6import source.SourceCode;
 7
 8public class Intervene extends SourceCode {
 9    public List<List<Double>> data = new ArrayList<>();
10
11    public static void main(String[] args) {
12        Intervene intervene = new Intervene();
13        intervene.testDemo001();
14    }
15
16    public void testDemo001() {
17        Point point1 = new Point(50, 50);
18        Point point2 = new Point(150, 50);
19        int lamda = 6;
20        for (int i = 0; i < 100; i++) {// y 轴
21            List<Double> distance = new ArrayList<>();
22            for (int j = 0; j < 200; j++) {// x 轴
23                Point point = new Point(j, i);
24                double x = point.distance(point1) % lamda / lamda;
25                double y = point.distance(point2) % lamda / lamda;
26                double xx = Math.sin(x * 2 * Math.PI);
27                double yy = Math.sin(y * 2 * Math.PI);
28                distance.add(xx + yy);
29            }
30            data.add(distance);
31        }
32        StringBuffer content = new StringBuffer();
33        int size = data.size();
34        for (int i = 0; i < size; i++) {
35            String text = data.get(i).toString();
36            text = text.substring(1, text.length() - 1);
37            if (i == 0)
38                content.append(text);
39            content.append(LINE + text);
40        }
41        logLong("intervene.log", content.toString());
42    }
43}

下面是生成图表:

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-10-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 FunTester 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档