Java Code Examples for org.jfree.chart.title.PaintScaleLegend#setMargin()

The following examples show how to use org.jfree.chart.title.PaintScaleLegend#setMargin() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RTMZPlot.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public RTMZPlot(RTMZAnalyzerWindow masterFrame, AbstractXYZDataset dataset,
    InterpolatingLookupPaintScale paintScale) {
  super(null);

  this.paintScale = paintScale;

  chart = ChartFactory.createXYAreaChart("", "Retention time", "m/z", dataset,
      PlotOrientation.VERTICAL, false, false, false);
  chart.setBackgroundPaint(Color.white);
  setChart(chart);

  // title

  TextTitle chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);
  chart.removeSubtitle(chartTitle);

  // disable maximum size (we don't want scaling)
  // setMaximumDrawWidth(Integer.MAX_VALUE);
  // setMaximumDrawHeight(Integer.MAX_VALUE);

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

  // set grid properties
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  plot.setDomainCrosshairPaint(crossHairColor);
  plot.setRangeCrosshairPaint(crossHairColor);
  plot.setDomainCrosshairStroke(crossHairStroke);
  plot.setRangeCrosshairStroke(crossHairStroke);

  NumberFormat rtFormat = MZmineCore.getConfiguration().getRTFormat();
  NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();

  // set the X axis (retention time) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setNumberFormatOverride(rtFormat);
  xAxis.setUpperMargin(0.001);
  xAxis.setLowerMargin(0.001);

  // set the Y axis (intensity) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setAutoRangeIncludesZero(false);
  yAxis.setNumberFormatOverride(mzFormat);

  plot.setDataset(dataset);
  spotRenderer = new RTMZRenderer(dataset, paintScale);
  plot.setRenderer(spotRenderer);
  spotRenderer.setDefaultToolTipGenerator(new RTMZToolTipGenerator());

  // Add a paintScaleLegend to chart

  paintScaleAxis = new NumberAxis("Logratio");
  paintScaleAxis.setRange(paintScale.getLowerBound(), paintScale.getUpperBound());

  paintScaleLegend = new PaintScaleLegend(paintScale, paintScaleAxis);
  paintScaleLegend.setPosition(plot.getDomainAxisEdge());
  paintScaleLegend.setMargin(5, 25, 5, 25);

  chart.addSubtitle(paintScaleLegend);

  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example 2
Source File: PlotUtil.java    From dl4j-tutorials with MIT License 4 votes vote down vote up
private static JFreeChart createChart(XYZDataset dataset, double[] mins, double[] maxs, int nPoints, XYDataset xyData) {
    NumberAxis xAxis = new NumberAxis("X");
    xAxis.setRange(mins[0],maxs[0]);


    NumberAxis yAxis = new NumberAxis("Y");
    yAxis.setRange(mins[1], maxs[1]);

    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth((maxs[0]-mins[0])/(nPoints-1));
    renderer.setBlockHeight((maxs[1] - mins[1]) / (nPoints - 1));
    PaintScale scale = new GrayPaintScale(0, 1.0);
    renderer.setPaintScale(scale);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    JFreeChart chart = new JFreeChart("", plot);
    chart.getXYPlot().getRenderer().setSeriesVisibleInLegend(0, false);


    NumberAxis scaleAxis = new NumberAxis("Probability (class 0)");
    scaleAxis.setAxisLinePaint(Color.white);
    scaleAxis.setTickMarkPaint(Color.white);
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7));
    PaintScaleLegend legend = new PaintScaleLegend(new GrayPaintScale(),
            scaleAxis);
    legend.setStripOutlineVisible(false);
    legend.setSubdivisionCount(20);
    legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    legend.setAxisOffset(5.0);
    legend.setMargin(new RectangleInsets(5, 5, 5, 5));
    legend.setFrame(new BlockBorder(Color.red));
    legend.setPadding(new RectangleInsets(10, 10, 10, 10));
    legend.setStripWidth(10);
    legend.setPosition(RectangleEdge.LEFT);
    chart.addSubtitle(legend);

    ChartUtilities.applyCurrentTheme(chart);

    plot.setDataset(1, xyData);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setBaseLinesVisible(false);
    plot.setRenderer(1, renderer2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    return chart;
}
 
Example 3
Source File: RTMZPlot.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public RTMZPlot(RTMZAnalyzerWindow masterFrame, AbstractXYZDataset dataset,
    InterpolatingLookupPaintScale paintScale) {
  super(null);

  this.paintScale = paintScale;

  chart = ChartFactory.createXYAreaChart("", "Retention time", "m/z", dataset,
      PlotOrientation.VERTICAL, false, false, false);
  chart.setBackgroundPaint(Color.white);
  setChart(chart);

  // title

  TextTitle chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);
  chart.removeSubtitle(chartTitle);

  // disable maximum size (we don't want scaling)
  setMaximumDrawWidth(Integer.MAX_VALUE);
  setMaximumDrawHeight(Integer.MAX_VALUE);

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

  // set grid properties
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  plot.setDomainCrosshairPaint(crossHairColor);
  plot.setRangeCrosshairPaint(crossHairColor);
  plot.setDomainCrosshairStroke(crossHairStroke);
  plot.setRangeCrosshairStroke(crossHairStroke);

  NumberFormat rtFormat = MZmineCore.getConfiguration().getRTFormat();
  NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();

  // set the X axis (retention time) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setNumberFormatOverride(rtFormat);
  xAxis.setUpperMargin(0.001);
  xAxis.setLowerMargin(0.001);

  // set the Y axis (intensity) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setAutoRangeIncludesZero(false);
  yAxis.setNumberFormatOverride(mzFormat);

  plot.setDataset(dataset);
  spotRenderer = new RTMZRenderer(dataset, paintScale);
  plot.setRenderer(spotRenderer);
  spotRenderer.setDefaultToolTipGenerator(new RTMZToolTipGenerator());

  // Add a paintScaleLegend to chart

  paintScaleAxis = new NumberAxis("Logratio");
  paintScaleAxis.setRange(paintScale.getLowerBound(), paintScale.getUpperBound());

  paintScaleLegend = new PaintScaleLegend(paintScale, paintScaleAxis);
  paintScaleLegend.setPosition(plot.getDomainAxisEdge());
  paintScaleLegend.setMargin(5, 25, 5, 25);

  chart.addSubtitle(paintScaleLegend);


  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}