1. 程式人生 > >計算beta分布並畫圖(2)

計算beta分布並畫圖(2)

except ont cat pos 數據統計 文件內容 sta () actor

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); } }

技術分享圖片

計算beta分布並畫圖(2)