Matplot3D for JAVA 【V5.0】发布 :一个纯JAVA开发的数学科学数据可视化组件,JAVA 三维绘图(可视化图表)组件,类似matplotlib
  81P87QOCeRAB 13天前 23 0

 Matplot3D for JAVA概述 

在数据科学和工程领域,数据可视化是理解和交流复杂信息的关键工具。如果您是一位Java开发者,寻找一个强大的、本地化的三维图形绘图库,那么Matplot3D for JAVA(V5.0)值得你关注。该组件旨在为Java开发者提供类似于Python中Matplotlib的三维绘图功能,让Java也能轻松绘制出令人印象深刻的3D图形图表。

Matplot3D for JAVA(V5.0) 是一个基于JAVA SE环境开发的三维图形图表组件。 组件由纯JAVA SE 实现(Pure Java) ,封装为一个jar包,jar文件大小只有300多KB。内含自主研发的软件三维几何造型和绘制算法,无需依赖OpenGL、DriectX、JAVA 3D或JAVAFX等等第三方库,其只依托JRE自带的默认类库即可(即只需安装了JAVA就可使用)。

Matplot3D for JAVA提供简洁明了的API设计,这使得即使是没有太多数据可视化工经验的开发者也可以快速上手构建出交互式的可视化应用。可用于大数据可视化、科学数学数据分析可视化等领域。它利用Java的自带的GUI框架构建界面同,确保了良好的跨平台兼容性同时能方便的集成到自己JAVA GUI程序中。也可以在服务端直接生成图片对象或文件,用于动态Web页面显示。

 


应用场景

  • 教学和研究:用于展示数学模型、物理现象和数据等。
  • 数据科学:在数据分析过程中可视化三维数据,帮助发现潜在模式。
  • 其他需要数据可视化的Java应用和系统

 


组件下载及项目地址:        

 


包文件说明

Matplot3d_4j_sydh_x64_V5.0.jar 为应用所需要依赖的包,仅将此包文件导入项目即可使用。(需要JAVA1.8 64bit 或以上,建议在JAVA17,JAVA21等LTS版本上使用或运行)

Matplot3d_4j_sydh_x64_V5.0_demo.jar 为演示DEMO的可执行的JAR文件,内含展示效果及部分示例代码 ( 使用时不需要引用这个包! )。在安装有64bit的JRE的电脑上一般双击运行即可(或者用命令行或批处理文件运行 ,运行的命令是:  "C:\Program Files\Java\....你的java安装根目录...\bin\java.exe" -jar Matplot3d_4j_sydh_x64_V5.0_demo.jar)。

 


V5.0 更新

v5.0版本的更新时一个较大的版本更新,更新内容主要包括:

  • 优化底层引擎算法,使之有更好的执行和刷新效率。
  • 重构部分了API,包括各处理器类和动画相关API等。
  • 增加实现画面发光效果的相关算法
  • 增加了网格映射曲面处理器(GridMeshProcessor),可以绘制复杂函数表达的映射曲面
  • 增加矢量场流线处理器(VectorFieldProcessor),可绘制空间矢量场的流线分布图和动画
  • 增加简单几何体处理器(Simple3DElementProcessor),可绘制长方体、柱体、椎体等。
  • 移除原FunctionProcessor类,其功能完全合并至DataGridProcessor类中。

 


样例展示

C60分子结构

 

网格映射曲面图

    Matplot3D for JAVA可用于绘制网格曲面,可以由两个独立自变量组成的经纬网格,通过映射函数映射到空间而形成的曲面

    莫比乌斯环曲面demo代码:

public class MobiusStripDemo {
	public static void main(String[] args) throws Exception {

		GridMeshProcessor processer = new GridMeshProcessor();

		Matplot3D4JMgr matPlot3DMgr = new Matplot3D4JMgr(processer);

		GridMeshMapper f = new GridMeshMapper() {

			public Point3D f(double d1, double d2) {

				double sita = d1;
				double offset = d2;

				double baseR = 12;// 半径

				double r = 3.6 * Math.cos(sita * 3 / 2) + baseR;

				double fai;// 自旋角

				fai = sita * 1.75;// 自旋角是方位角的1.75

				double x = (r + (offset * Math.cos(fai))) * Math.cos(sita);
				double y = (r + (offset * Math.cos(fai))) * Math.sin(sita);
				double z = offset * Math.sin(fai) + 3.6 * Math.sin(sita * 3 / 2);

				return new Point3D(x, y, z);
			}

			public void setAdditionalPrar(Object additionalprar) {}
		};

		double[] sita = FunctionSpaceUtil.lineSpace(0, Math.PI * 4, 300);

		double[] offset = FunctionSpaceUtil.lineSpace(-3.1, 3.1, 5);

		processer.addData(f, sita, offset, "1",new TopBottomColorStyle(ColorStyle.DEFAULT_COLORS_REVERSE_ARRAY) ,1f);

		matPlot3DMgr.setCoordianteSysShowType(matPlot3DMgr.COORDINATE_SYS_ALWAYS_FURTHER);
		matPlot3DMgr.setTitle("Mobius strip demo");

		matPlot3DMgr.show();
	}
}

  

 矢量场流线图

    Matplot3D for JAVA可用于近似模拟生成空间矢量场的流线分布图。

 

   简单样例代码

public class SimpleVectorFieldDemo {
	public static void main(String[] args) {

		VectorFieldProcessor processer = new VectorFieldProcessor();

		Matplot3D4JMgr matPlot3DMgr = new Matplot3D4JMgr(processer);

		Vector3D v1 = new Vector3D(1, 0, 0);
		Vector3D v2 = new Vector3D(-0.1, 0, 0);
		Vector3D vNull = new Vector3D(0, 0, 0);

		class MyMapper1 implements Point3dVector3dMapper {
			public Vector3D f(Point3D p) {
				if (p.y() > 0) {
					return v1;
				} else {
					return vNull;
				}
			}

			public void setAdditionalPrar(Object additionalprar) {}
		}

		class MyMapper2 implements Point3dVector3dMapper {
			public Vector3D f(Point3D p) {
				if (p.y() < 0) {
					return v2;
				} else {
					return vNull;
				}
			}

			public void setAdditionalPrar(Object additionalprar) {}
		}

		processer.addData(new MyMapper1(), "1", Color.RED, new Range(-9, 9), new Range(-9, 9), new Range(-9, 9));

		processer.addData(new MyMapper2(), "2", Color.BLUE, new Range(-9, 9), new Range(-9, 9), new Range(-9, 9));

		List<Point3D> seeds = new ArrayList<Point3D>();

		for (double z = -9; z <= 9; z += 1.2) {
			for (double y = -9; y <= 9; y += 1.2) {
				seeds.add(new Point3D(0, y, z));
			}
		}

		processer.setPropertyToAll("seeds", seeds);
		processer.setPropertyToAll("alphaNoise", 0.0);

		matPlot3DMgr.setTitle("矢量场流线");
		matPlot3DMgr.setAppearanceTheme(Matplot3D4JMgr.APPEARANCE_THEME_DARK);

		matPlot3DMgr.showMotion(-1, 15, 0);
	}
}

数据阵列网格曲面

    Matplot3D for JAVA 可以用于生成以xy方向均匀分布高程点阵组成的网格或连续曲面 ,可用于绘制高程图等。

    函数曲面demo代码:

public class FunctionSurfaceDemo {
	public static void main(String[] args) {

		DataGridProcessor processor = new DataGridProcessor();
		
		final Matplot3D4JMgr mgr=new Matplot3D4JMgr(processor);		

		//定义二维函数,根据xy值求y值
		Function f = new Function() {
			public Double f(double x, double y) {
				return Math.sin(y * x / 2.2) * 0.8;
			}
		};

		double pi = Math.PI;

		//将二维函数加入处理器,设置XY方向显示范围和采样分段数
		Range rangeX = new Range(-1.5 * pi, 1.5 * pi);
		Range rangeY = new Range(-1.5 * pi, 1.5 * pi);

		// 将二维函数加入处理器,设置XY方向显示范围和采样分段数
		processor.addData(
            FunctionSpaceUtil.getDataByFunction(f, rangeX, rangeY, 200, 300), 
            "", rangeX, rangeY, new TopBottomColorStyle(), 1f);
		
		processor.setPropertyToAll("isDoubleSide", true);
		processor.setPropertyToAll("isShowGrid", false);

		mgr.setScaleZ(1.5);
		mgr.setScaleX(1.3);
		mgr.setScaleY(1.3);

		mgr.setTitle("Demo : 函数曲面绘制   [ z =  0.8 * sin(y*x/2.2) ]");

		mgr.setCoordianteSysShowType(mgr.COORDINATE_SYS_ALWAYS_FURTHER);

		mgr.show();
}

 

曲面云图

    Matplot3D for JAVA可绘制曲面云图。“云图”包含xyz三个空间量以外还会显示第4个独立的标量(例如温度、压强、流速率等等)的分布,第4个量强弱由颜色序列来表示。

   

    简单样例代码:

public class ContourDataGridDemo {
	public static void main(String[] args) {
		
		ContourDataGridProcessor processor = new ContourDataGridProcessor();
		
		Matplot3D4JMgr mgr=new Matplot3D4JMgr(processor);		
		
		//=======================================
		//准备你的高度数据,是一个二维Double数组。表示均匀分布的网格点,数组内的值表示高度
		//数据一般来源于具体应用的非规则函数数据,例如某区域的DEM地形高程数据
		//以下代码创造一些虚拟数据用于展示如何使用
		
		Double[][] datas=new Double[100][100];
		
		for(int i=0;i<datas.length;i++) {
			for(int j=0;j<datas[0].length;j++) {
		
				datas[i][j]=-0.1*Math.pow(100d-i-j,2)+1000;
				
			}
		}

		//=======================================
		//准备你的显示数据values,是一个二维Double数组,。表示均匀分布的网格点,数组内的值表示非xyz的第四维标量数据
		//values的行列分布可以不与datas一致,但建议最好一致以优化显示效果
		//以下代码创造一些虚拟数据用于展示如何使用
		
		Double[][] values=new Double[50][50];
		for(int i=0;i<values.length;i++) {
			for(int j=0;j<values[0].length;j++) {
				double temp=Math.sqrt(Math.pow(i-25d,2)+Math.pow(j-25d,2));
				values[i][j]=temp;
			}
		}

		Color baseColor=Color.GRAY;//云图需要一个基色
		
		processor.addData(datas, values,baseColor, "my_name", new Range(0, 100), new Range(100, 200), 20, 20, 1f);
		
		processor.setClose3DObject(true);//设置是否是封闭三维对象

		mgr.setCoordianteSysShowType(Matplot3D4JMgr.COORDINATE_SYS_ALWAYS_FURTHER);
		
		mgr.setScaleX(5);
		mgr.setScaleY(5);
		mgr.setScaleZ(0.2);

		mgr.setTitle("曲面云图简单样例");
		
		mgr.show();
	}
}

 

通用网格曲面

    Matplot3D for JAVA 可绘制难以用函数关系表示的自定义的网格或者多边形,可通过输入顶点的位置、小三角形或者四边形单元信息来组合成复杂三维图形 。

 

三维散点图

    Matplot3D for JAVA 可用于绘制分组散点图或者显示点云。

   

    散点图demo代码:

public class ScatterDemo {

	public static void main(String[] args) throws Exception {
	
		ScatterDataProcessor processor = new ScatterDataProcessor();

		final Matplot3D4JMgr mgr=new Matplot3D4JMgr(processor);		

		//*************************************************************//
		//在此准备数据,将Point3D对象放入List<Point3D>容器中
		List<Point3D> dos1=new ArrayList<Point3D>();
		List<Point3D> dos2=new ArrayList<Point3D>();
		List<Point3D> dos3=new ArrayList<Point3D>();
		
		Random ram=new Random();
		
		for(int i=0;i<100;i++) {
			
			dos1.add(new Point3D(ram.nextDouble()+1,ram.nextDouble(),ram.nextDouble()+1));
			dos2.add(new Point3D(ram.nextDouble()+1,ram.nextDouble()+1,ram.nextDouble()));
			dos3.add(new Point3D(ram.nextDouble(),ram.nextDouble()+1,ram.nextDouble()));
		}
		
		//加入第一组数据
		processor.addData("Item 1", dos1);
	    
		//加入第二组数据
		processor.addData("Item 2", dos2);
		
		//加入第三组数据
		processor.addData("Item 3", dos3);
		
		processor.setPropertyToAll("isShowEdge", true);
		
		mgr.setTitle("散点图");

		//坐标参考平面不会遮挡数据
		mgr. setCoordianteSysShowType( Matplot3D4JMgr.COORDINATE_SYS_ALWAYS_FURTHER);

		mgr.show();
	}
}

 

简单几何体组合图形

    Matplot3D for JAVA 用于绘制圆柱、长方体等简单几何体的组合图形。

 

    绘制简单几何体代码:

public class SimpleElementsDemo {
	public static void main(String[] args) throws Exception {
		
		Simple3DElementProcessor processor = new Simple3DElementProcessor();

		final Matplot3D4JMgr mgr=new Matplot3D4JMgr(processor);		
		
		processor.addSphere(new Point3D(-1.5,1.5,0 ), 1,39,20, Color.YELLOW);
		
		processor.addCuboid(new Point3D(1.5,1.5,0 ), 1.3,1.5,1.7, Color.GREEN);

		processor.addCone(new Point3D(-1.5,-1.5,-0.9 ), new Point3D(-1.5,-1.5,1.0 ),1,30, Color.RED);
		
		processor.addCylinder(new Point3D(1.5,-1.5,-0.9 ), new Point3D(1.5,-1.5,1.0 ),1,30, Color.BLUE);

		mgr.setTitle("简单几何体");
	    
		mgr. setCoordianteSysShowType( Matplot3D4JMgr.COORDINATE_SYS_ALWAYS_FURTHER);

		mgr.show();
	}
}

 

三维瀑布图

    Matplot3D for JAVA 可用于绘制三维瀑布图

 

    简单样例代码:

public class SimpleWaterfallDemo {
	public static void main(String[] args) {
	
		Waterfall3DProcessor processer = new Waterfall3DProcessor();
		Matplot3D4JMgr mgr = new Matplot3D4JMgr(processer);

		int stepC = 300;
		double step = 0.05;

		processer.setGroupSpacing(1);//设置间距为1

		//第一组图形
		List<Point2D.Double> li1 = new ArrayList<Point2D.Double>();

		for (int i = 0; i < stepC; i++) {
			li1.add(new Point2D.Double(i * step, Math.sin(i * step)));
		}

		processer.addData("Item 1", null, li1);
		
		//第二组图形
		List<Point2D.Double> li2 = new ArrayList<Point2D.Double>();

		for (int i = 0; i < stepC; i++) {
			li2.add(new Point2D.Double(i * step, Math.cos(i * step)));
		}

		processer.addData("Item 2", null, li2);

		processer.setBaseZ(-1); 

		mgr.setScaleZ(1.5);

		mgr.show();
	}
}

 

三维柱状图

    Matplot3D for JAVA 可用于绘制三维柱状图

   

    绘制简单柱状图代码:

public class BarsDemo {
	public static void main(String[] args) {
		
		BarProcessor processor = new BarProcessor();

		Matplot3D4JMgr mgr = new Matplot3D4JMgr(processor);
		

		// ===========================================
		// 在此准备数据
		// 每组数据在一个或多个二维数组中,数组中表示柱体高度(标1表示组号,相同组号同颜色;下标2表示同组中的不同列)

		Double[][] ds1 = new Double[][] { 
                { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 },
				{ 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 },
                { 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 } 
        };

		Color c1 = Color.RED;
		Color c2 = Color.GREEN;
		Color c3 = new Color(80, 80, 255);

		Color[][] colors = new Color[][] {
                { c1, c1, c1, c1, c1, c1, c1, c1 }, 
                { c2, c2, c2, c2, c2, c2, c2, c2 },
				{ c3, c3, c3, c3, c3, c3, c3, c3 } 
        };

		Color ce = Color.BLACK;

		Color[][] ecolors = new Color[][] { 
                { ce, ce, ce, ce, ce, ce, ce, ce }, 
                { ce, ce, ce, ce, ce, ce, ce, ce },	
                { ce, ce, ce, ce, ce, ce, ce, ce } 
        };

		processor.addData("项目1", ds1,colors,ecolors);

		processor.setBarWidthX(2);
		processor.setBarWidthY(2);

		processor.setxSpace(0.2);
		processor.setySpace(1);
		processor.setSpaceInBundle(0.3);

		//自定义标签图例面板
		KeyLabelLegend legend = new KeyLabelLegend();
		legend.put("项目A", c1);
		legend.put("项目B", c2);
		legend.put("项目C", c3);

		mgr.addLegend(legend);

		mgr.setScaleZ(1.5);
		mgr.setScaleX(1.3);

		mgr.setTitle("柱状图");

		mgr.setElevation(0.2);
		mgr.setAzimuth(2.2);

		mgr.show();
	}
}

三维曲线/折线图

    绘制空间折线、曲线、线段等。

 

    简单样例代码:

public class CurveDemo {

	public static void main(String[] args) throws Exception {
	
		CurveProcessor processor = new CurveProcessor();

		final Matplot3D4JMgr mgr=new Matplot3D4JMgr(processor);		
		
		List<Point3D> list=new ArrayList<Point3D>();
		
		list.add(new Point3D(0, 0, 0));
		list.add(new Point3D(0, 0, 1));
		list.add(new Point3D(1, 0, 1));
		list.add(new Point3D(1, 0.3, 0));
		list.add(new Point3D(1, 0.7, 0));
		list.add(new Point3D(1, 1, 1));
		list.add(new Point3D(0, 1, 1));
		list.add(new Point3D(0, 1, 0));
		
		processor.addData(list, "折线A", Color.RED, 1);

		mgr.setTitle("三维折线");
		
		mgr.setElevation(0.06);
		mgr.setAzimuth(0.36);

		mgr. setCoordianteSysShowType( Matplot3D4JMgr.COORDINATE_SYS_ALWAYS_FURTHER);

		mgr.show();
	}
}

 

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 13天前 0

暂无评论

推荐阅读
  oXKBKZoQY2lx   2024年03月19日   75   0   0 计算机图形学
81P87QOCeRAB