利用 python+plotly 製做雙波源干涉三維圖像

本人在學習完製做雙波源干涉現象的的二維Contour Plots圖像以後,發現 plotly 還有3D 圖像製做,也就是3D Surface Plots,這個更能展現雙波源干涉現象的結果,果真學之。中間有些地方要說明一下,3D Surface Plots圖表默認的底部是正方形,因此我採用了100*100的干涉圖,而後加上一層透明的圖標,讓圖像壓扁,否則圖標的上下限就是波動位置,看起來很是不雅觀。html

下面分享代碼和結果:java

下面是 python部分的代碼:python

#!/usr/bin/python
# coding=utf-8
 
import plotly.plotly
 
z = []
with open("/Users/Vicky/Documents/workspace/fission/long/intervene.log") as apidata:
    for i in apidata:
        data = i.split("\n")[0].split(",")
        z.append(data)
matrix = [[20 for zij in zi] for zi in z]#爲了讓立體圖壓扁
plotly.offline.plot([
     dict(
            z=z,
            type="surface"
    ),
    dict(
            z=matrix,
            showscale=False,
            opacity=0.01,#透明度
            type="surface"
    )
], filename="2222.html")

下面是 java 部分的代碼,是爲了生成數據:編程

package practise;
 
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import source.SourceCode;
 
public class Intervene extends SourceCode {
	public List<List<Double>> data = new ArrayList<>();
 
	public static void main(String[] args) {
		Intervene intervene = new Intervene();
		intervene.testDemo001();
	}
 
	public void testDemo001() {
		Point point1 = new Point(25, 25);
		Point point2 = new Point(75, 75);
		int lamda = 6;
		for (int i = 0; i < 100; i++) {// y 軸
			List<Double> distance = new ArrayList<>();
			for (int j = 0; j < 100; j++) {// x 軸
				Point point = new Point(j, i);
				double x = point.distance(point1) % lamda / lamda;
				double y = point.distance(point2) % lamda / lamda;
				double xx = Math.sin(x * 2 * Math.PI);
				double yy = Math.sin(y * 2 * Math.PI);
				distance.add(xx + yy);
			}
			data.add(distance);
		}
		StringBuffer content = new StringBuffer();
		int size = data.size();
		for (int i = 0; i < size; i++) {
			String text = data.get(i).toString();
			text = text.substring(1, text.length() - 1);
			if (i == 0)
				content.append(text);
			content.append(LINE + text);
		}
		logLong("intervene.log", content.toString());
	}
}

下面是3D Surface Plots圖的截圖: 2018030609234447.pngapi

20180306092335285.png

技術類文章精選

非技術文章精選

大咖風采

點擊查看公衆號地圖

相關文章
相關標籤/搜索