计算beta分布并画图(2)

2018-06-18 02:49:33来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

import java.awt.Font;
import java.awt.GridLayout;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import zxy.nlp.lda.conf.PathConfig;


public class plotbetadis {
    ChartPanel frame1;    
    public  plotbetadis() throws IOException{  
            DefaultCategoryDataset dataset = (DefaultCategoryDataset) createDataset();  
            JFreeChart chart = ChartFactory.createLineChart("","date", "topic intensity/%",dataset,PlotOrientation.VERTICAL, true, true, true);  
          
            CategoryPlot plot=chart.getCategoryPlot();
            NumberAxis numberaxis = (NumberAxis)plot.getRangeAxis();
            numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());           
            numberaxis.setLabelFont(new Font("黑体",Font.BOLD,14));         //水平底部标题  
            numberaxis.setTickLabelFont(new Font("宋体",Font.BOLD,12));  //垂直标题                     
            frame1=new ChartPanel(chart,true);
            chart.getLegend().setItemFont(new Font("黑体", Font.BOLD, 15));  
            chart.getTitle().setFont(new Font("宋体",Font.BOLD,20));//设置标题字体  
      
        }  
               
        
         private static CategoryDataset createDataset() throws IOException { 
             
             DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();             
             
             int lnum=2;
             String resPath = PathConfig.LdaResultsPath;
             String modelName = "ldatimes";
             FileReader fr=new FileReader(filename);
                                  
             double[][] nodes = new double[lnum][];
             String[] lines;
                
             //System.out.println("以行为单位读取文件内容,一次读一整行:");
             BufferedReader br=new BufferedReader(fr);
             String line = null;
             int x=0;

            // 一次读入一行,直到读入null为文件结束
             while ((line = br.readLine()) != null && x<lnum) {
                
                    // 显示行号
                    //System.out.println("line " + lnum + ": " + line);
                    lines = line.split("\t");
//                                for (int i = 0; i < lines.length; i++) {
//                                    System.out.println("一维 :" + lines[i] + "   ");
//                                }
                    nodes[x] = new double[lines.length];
                    for (int y = 0; y < lines.length; y++) {
                        
                        nodes[x][y] = Double.parseDouble(lines[y]);  
                        String s = String.valueOf((y+4)/4);
                        String t = String.valueOf(x);
                        defaultcategorydataset.addValue(nodes[x][y], "top"+t, s);
                    }
                    x++;
                    //lines = null;
                
             }
             br.close();
                     
             return defaultcategorydataset;  
            }  
         public ChartPanel getChartPanel(){  
                return frame1; 
         }         
            
         public static void main(String args[]) throws IOException{
              JFrame frame=new JFrame("数据统计图");  
              frame.setLayout(new GridLayout(2,2,5,5)); 
              frame.add(new plotbetadis().getChartPanel());    //添加折线图  
              frame.setBounds(50, 50, 600, 600);  
              frame.setVisible(true);  
          }
    
}

 

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:SpringVC 拦截器+自定义注解 实现权限拦截

下一篇:Spring入门看这一篇就够了