java 画数学函数图不太方便,需要用第三方包 jfree,安装或下载方法网上有。

要用到 jfree 里面的 XYSeries,生成一系列数据。

然后根据生成的数据,使用 chart 描点画图。

举例:

1. 画图 y= x^2

import javax.swing.JFrame;import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;public class DrawMath {public static void main(String[] args) {XYSeries series = new XYSeries("xySeries");for (int x = -100; x < 100; x++) {int y = x*x;series.add(x, y);}XYSeriesCollection dataset = new XYSeriesCollection();dataset.addSeries(series);JFreeChart chart = ChartFactory.createXYLineChart("y = x^2", // chart title"x", // x axis label"x^2", // y axis labeldataset, // dataPlotOrientation.VERTICAL,false, // include legendfalse, // tooltipsfalse // urls);ChartFrame frame = new ChartFrame("my picture", chart);frame.pack();frame.setVisible(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}}

显示效果:

2. 画图 y= sin(x)

import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;public class DrawMath {public static void main(String[] args) {XYSeries series = new XYSeries("xySeries");for (double x = -10; x < 10; x = x + 0.1) {double y = Math.sin(x);series.add(x, y);}XYSeriesCollection dataset = new XYSeriesCollection();dataset.addSeries(series);JFreeChart chart = ChartFactory.createXYLineChart("y = sin(x)", // chart title"x", // x axis label"sin(x)", // y axis labeldataset, // dataPlotOrientation.VERTICAL,false, // include legendfalse, // tooltipsfalse // urls);ChartFrame frame = new ChartFrame("my picture", chart);frame.pack();frame.setVisible(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   }
}

显示效果:

3. 画散点图

画散点图时,要用到 plot 与 render 进一步设置了。

举例:

import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;public class DrawMath {public static void main(String[] args) {XYSeries series = new XYSeries("xySeries");for (double x = -10; x < 10; x = x + 0.1) {double y = Math.sin(x);series.add(x, y);}XYSeriesCollection dataset = new XYSeriesCollection();dataset.addSeries(series);JFreeChart chart = ChartFactory.createXYLineChart("y = sin(x)", // chart title"x", // x axis label"sin(x)", // y axis labeldataset, // dataPlotOrientation.VERTICAL,false, // include legendfalse, // tooltipsfalse // urls);XYPlot plot = (XYPlot)chart.getPlot();XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();renderer.setSeriesLinesVisible(0, false); // 设置连线不可见plot.setRenderer(renderer);ChartFrame frame = new ChartFrame("my picture", chart);frame.pack(); // fit window to figure sizeframe.setVisible(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    }
}

显示效果:

java 画数学函数图相关推荐

  1. 用python画数学函数图像教程_你知道哪些用计算机画数学函数图象的方法?

    最近正好在找画图方法,我知道的就是下面这些: 用matlab.octave.scilab(就是那几个plot命令) 这类软件 用opengl(有点杀鸡用牛刀的味道) 用gnuplot(用起来很简单.可 ...

  2. python画函数曲线-使用Python画数学函数曲线

    import numpy as np import pandas as pd import matplotlib.pyplot as plt plt.figure(1) # 创建图表1 plt.fig ...

  3. python画数学函数_Python 绘制你想要的数学函数图形

    Python 非常热门,但除非工作需要没有刻意去了解更多,直到有个函数图要绘制,想起了它.结果发现,完全用不着明白什么是编程,就可以使用它完成很多数学函数图的绘制.通过以下两个步骤,就可以进行数学函数 ...

  4. 用python画数学函数图像教程_Python 绘制你想要的数学函数图形

    Python 非常热门,但除非工作需要没有刻意去了解更多,直到有个函数图要绘制,想起了它.结果发现,完全用不着明白什么是编程,就可以使用它完成很多数学函数图的绘制. 通过以下两个步骤,就可以进行数学函 ...

  5. python画数学函数_Python 绘制你想要的数学函数图形 !

    Python 非常热门,但除非工作需要没有刻意去了解更多,直到有个函数图需要绘制,想起了它.结果发现,完全用不着明白什么是编程,就可以使用它完成很多数学函数图的绘制.通过以下两个步骤,就可以进行数学函 ...

  6. 用c语言绘制数学函数图像,用c语言画数学函数图像.DOC

    用c语言画数学函数图像 时间:2007-02-13 作者:佚名 编辑:本站 点击: 2231 [评论] 符 outtextxy(CX+3,440-40*i,s); //以字符形式输出纵轴上的单位数字 ...

  7. python 画任意函数曲线_使用Python画数学函数曲线

    import numpy as np import pandas as pd import matplotlib.pyplot as plt plt.figure(1) # 创建图表1 plt.fig ...

  8. python 画三维函数图-Python画三维图-----插值平滑数据

    一.二维的插值方法: 原始数据(x,y) 先对横坐标x进行扩充数据量,采用linspace.[如下面例子,由7个值扩充到300个] 采用scipy.interpolate中的spline来对纵坐标数据 ...

  9. python学习-画数学函数

    简单学习python显示数学函数 基本显示高斯函数 丰富内容 注释特殊点 基本显示高斯函数 import numpy as np #numpy为数学库 import matplotlib.pyplot ...

最新文章

  1. ITK:计算图像谱密度
  2. 随着互联网的深化,世间万物都将如何学会思考?
  3. qregexp限制数字范围_数字系统实现电压电流控制的必经之路数模转换器
  4. hana抽数到mysql,HANA数据库管理Tenant DB常用操作
  5. .NET 客户IP地址捕捉
  6. 文本情感分析(介绍文章)--总结
  7. Net硅谷动力网站 http://www.enet.com.cn/
  8. spring5、springboot和springcloud的区别
  9. 软路由安装php,爱快软路由上安装黑群晖方法教程
  10. 权健和束昱辉传销为啥这么多?
  11. Cocos Create 3.3 打包安卓apk
  12. up考研资料更新目录
  13. “知识共享”实例:鲁宾逊微积分轮番投放全国高校三月有余
  14. 阿里巴巴开源的 Java 诊断工具Arthas【入门篇】
  15. docker及私有仓库harbor安装实践
  16. es sql实现分页
  17. PHP中给数组中追加元素
  18. 11月14日火箭vs灰熊视频直播在线观看
  19. js 传入字符串,转换成日期类型,如果转换失败返回null
  20. day 5 文字溢出处理 背景图片处理 开发经验

热门文章

  1. 使用再生龙clonezilla对win10和ubuntu16的双系统备份与还原
  2. 中南大学计算机学硕很难考吗,2019中南大学计算机专业考研成功经验分享
  3. gradle mapstruct 提升警告: Unmapped target property: “
  4. Number - 十进制和二进制互相转换
  5. 佛山顺德计算机美工培训班,顺德区电子商务美工培训
  6. 天有不测风云 | 智能车线上比赛一些意外情况
  7. 图腾标准服务器机柜型号,图腾常用的机柜型号及全参数
  8. 刮刮乐、幸运大转盘 1
  9. 索泰新款 ZBox 怎么样
  10. mess组网 中继_土豪用Mesh 我们就用无线中继解决问题