MATSIM
BoxPlotErrorGraph.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * BoxPlotErrorGraph.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.counts.algorithms.graphs;
22 
23 import java.awt.Color;
24 import java.awt.Font;
25 import java.util.ArrayList;
26 import java.util.List;
27 
28 import org.jfree.chart.JFreeChart;
29 import org.jfree.chart.axis.CategoryAxis;
30 import org.jfree.chart.axis.CategoryLabelPositions;
31 import org.jfree.chart.axis.NumberAxis;
32 import org.jfree.chart.labels.BoxAndWhiskerToolTipGenerator;
33 import org.jfree.chart.plot.CategoryPlot;
34 import org.jfree.chart.plot.CombinedDomainCategoryPlot;
35 import org.jfree.chart.renderer.category.BoxAndWhiskerRenderer;
36 import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset;
38 
39 public final class BoxPlotErrorGraph extends CountsGraph {
40 
41  public BoxPlotErrorGraph(final List<CountSimComparison> ccl, final int iteration, final String filename,
42  final String chartTitle) {
43  super(ccl, iteration, filename, chartTitle);
44  }
45 
46  @Override
47  public JFreeChart createChart(final int nbr) {
48 
49  DefaultBoxAndWhiskerCategoryDataset dataset0 = new DefaultBoxAndWhiskerCategoryDataset();
50  DefaultBoxAndWhiskerCategoryDataset dataset1 = new DefaultBoxAndWhiskerCategoryDataset();
51 
52  final ArrayList<Double>[] listRel = new ArrayList[24];
53  final ArrayList<Double>[] listAbs = new ArrayList[24];
54 
55  // init
56  for (int i = 0; i < 24; i++) {
57  listRel[i] = new ArrayList<Double>();
58  listAbs[i] = new ArrayList<Double>();
59  }
60 
61  // add the values of all counting stations to each hour
62  for (CountSimComparison cc : this.ccl_) {
63  int hour = cc.getHour() - 1;
64  listRel[hour].add(cc.calculateRelativeError() * 100);
65  listAbs[hour].add(cc.getSimulationValue() - cc.getCountValue());
66  }
67 
68  // add the collected values to the graph / dataset
69  for (int i = 0; i < 24; i++) {
70  dataset0.add(listRel[i], "Rel Error", Integer.toString(i + 1));
71  dataset1.add(listAbs[i], "Abs Error", Integer.toString(i + 1));
72  }
73 
74  String title = "Iteration: " + this.iteration_;
75 
76  final CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot();
77 
78  final CategoryAxis xAxis = new CategoryAxis("Hour");
79  final NumberAxis yAxis0 = new NumberAxis("Signed Rel. Error [%]");
80  final NumberAxis yAxis1 = new NumberAxis("Signed Abs. Error [veh]");
81  yAxis0.setAutoRangeIncludesZero(false);
82  yAxis1.setAutoRangeIncludesZero(false);
83 
84  final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
85  renderer.setFillBox(false);
86  renderer.setSeriesPaint(0, Color.blue);
87  renderer.setSeriesToolTipGenerator(0, new BoxAndWhiskerToolTipGenerator());
88 
89  CategoryPlot subplot0 = new CategoryPlot(dataset0, xAxis, yAxis0, renderer);
90  CategoryPlot subplot1 = new CategoryPlot(dataset1, xAxis, yAxis1, renderer);
91 
92  plot.add(subplot0);
93  plot.add(subplot1);
94 
95  final CategoryAxis axis1 = new CategoryAxis("hour");
96  axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
97  axis1.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
98  plot.setDomainAxis(axis1);
99 
100  this.chart_ = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 14), plot, false);
101  return this.chart_;
102  }
103 }
BoxPlotErrorGraph(final List< CountSimComparison > ccl, final int iteration, final String filename, final String chartTitle)