List of usage examples for org.jfree.chart.axis LogAxis setStandardTickUnits
public void setStandardTickUnits(TickUnitSource source)
From source file:umberto.WeightedClusterCoefficient.ChartUtils.java
public static void scaleLogChart(JFreeChart chart, XYSeries dSeries, boolean normalized) { XYPlot plot = (XYPlot) chart.getPlot(); final LogAxis logyAxis = new LogAxis(plot.getRangeAxis().getLabel()); final LogAxis logxAxis = new LogAxis(plot.getDomainAxis().getLabel()); //Set y axis format. // DecimalFormat formaty = (DecimalFormat) DecimalFormat.getNumberInstance(Locale.ENGLISH); // formaty.applyPattern("#0.0000"); //set y axis/* w ww .ja v a 2 s.com*/ logyAxis.setBase(10); // logyAxis.setNumberFormatOverride(formaty); logyAxis.setStandardTickUnits(LogAxis.createLogTickUnits(Locale.ENGLISH)); // logyAxis.setRange(0.01, 1.0); logyAxis.setAutoRange(true); plot.setRangeAxis(logyAxis); //set x axis logxAxis.setBase(10); logxAxis.setStandardTickUnits(LogAxis.createLogTickUnits(Locale.ENGLISH)); logxAxis.setAutoRange(true); //logxAxis.setRange(0.00001, 1.0);//Se la voglio zoommare plot.setDomainAxis(logxAxis); }
From source file:org.gwaspi.reports.GenericReportGenerator.java
private static void appendToCombinedRangeManhattanPlot(CombinedRangeXYPlot combinedPlot, String chromosome, XYSeriesCollection currChrSC, boolean showlables, double threshold, Color background, Color backgroundAlternative, Color main) { XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); // Set dot shape of the currently appended Series renderer.setSeriesPaint(currChrSC.getSeriesCount() - 1, main); renderer.setSeriesVisibleInLegend(currChrSC.getSeriesCount() - 1, showlables); renderer.setSeriesShape(currChrSC.getSeriesCount() - 1, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0)); // Set range axis if (combinedPlot.getSubplots().isEmpty()) { LogAxis rangeAxis = new LogAxis("P value"); rangeAxis.setBase(10);/*from w ww . j a v a2s .co m*/ rangeAxis.setInverted(true); rangeAxis.setNumberFormatOverride(FORMAT_P_VALUE); rangeAxis.setTickMarkOutsideLength(2.0f); rangeAxis.setMinorTickCount(2); rangeAxis.setMinorTickMarksVisible(true); rangeAxis.setAxisLineVisible(true); rangeAxis.setUpperMargin(0); TickUnitSource units = NumberAxis.createIntegerTickUnits(); rangeAxis.setStandardTickUnits(units); combinedPlot.setRangeAxis(0, rangeAxis); } // Build subchart JFreeChart subchart = ChartFactory.createScatterPlot("", "Chr " + chromosome, "", currChrSC, PlotOrientation.VERTICAL, false, false, false); // Get subplot from subchart XYPlot subplot = (XYPlot) subchart.getPlot(); subplot.setRenderer(renderer); subplot.setBackgroundPaint(null); // CHART BACKGROUD COLOR if (combinedPlot.getSubplots().size() % 2 == 0) { subplot.setBackgroundPaint(background); // Hue, saturation, brightness } else { subplot.setBackgroundPaint(backgroundAlternative); // Hue, saturation, brightness } // Add significance Threshold to subplot final Marker thresholdLine = new ValueMarker(threshold); thresholdLine.setPaint(Color.red); // Add legend to hetzyThreshold if (showlables) { thresholdLine.setLabel("P = " + FORMAT_P_VALUE.format(threshold)); } thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT); thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); subplot.addRangeMarker(thresholdLine); // Chromosome Axis Labels NumberAxis chrAxis = (NumberAxis) subplot.getDomainAxis(); chrAxis.setLabelAngle(1.0); chrAxis.setAutoRangeIncludesZero(false); chrAxis.setAxisLineVisible(true); chrAxis.setTickLabelsVisible(false); chrAxis.setTickMarksVisible(false); // chrAxis.setNumberFormatOverride(Report_Analysis.FORMAT_SCIENTIFIC); // TickUnitSource units = NumberAxis.createIntegerTickUnits(); // chrAxis.setStandardTickUnits(units); //combinedPlot.setGap(0); combinedPlot.add(subplot, 1); }
From source file:com.wattzap.view.graphs.MMPGraph.java
public MMPGraph(XYSeries series) { super();//from w ww . j a v a 2s . c o m NumberAxis yAxis = new NumberAxis(userPrefs.messages.getString("poWtt")); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); double maxY = series.getMaxY(); yAxis.setRange(0, maxY + 20); yAxis.setTickLabelPaint(Color.white); yAxis.setLabelPaint(Color.white); LogAxis xAxis = new LogAxis(userPrefs.messages.getString("time")); xAxis.setTickLabelPaint(Color.white); xAxis.setBase(4); xAxis.setAutoRange(false); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); xAxis.setRange(1, series.getMaxX() + 500); xAxis.setNumberFormatOverride(new NumberFormat() { @Override public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { long millis = (long) number * 1000; if (millis >= 60000) { return new StringBuffer(String.format("%d m %d s", TimeUnit.MILLISECONDS.toMinutes((long) millis), TimeUnit.MILLISECONDS.toSeconds((long) millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis)))); } else { return new StringBuffer(String.format("%d s", TimeUnit.MILLISECONDS.toSeconds((long) millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis)))); } } @Override public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { return new StringBuffer(String.format("%s", number)); } @Override public Number parse(String source, ParsePosition parsePosition) { return null; } }); XYPlot plot = new XYPlot(new XYSeriesCollection(series), xAxis, yAxis, new XYLineAndShapeRenderer(true, false)); JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(Color.gray); plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.darkGray); /*plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray);*/ ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelPaint(Color.white); domainAxis.setLabelPaint(Color.white); chartPanel = new ChartPanel(chart); chartPanel.setSize(100, 800); chartPanel.setFillZoomRectangle(true); chartPanel.setMouseWheelEnabled(true); chartPanel.setBackground(Color.gray); setLayout(new BorderLayout()); add(chartPanel, BorderLayout.CENTER); setBackground(Color.black); chartPanel.revalidate(); setVisible(true); }
From source file:org.gwaspi.gui.reports.ManhattanPlotZoom.java
private JFreeChart createChart(XYDataset dataset, ChromosomeKey chr) { JFreeChart chart = ChartFactory.createScatterPlot(null, "", "P value", dataset, PlotOrientation.VERTICAL, true, false, false);//from w w w . j a va2 s.c om XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); // CHART BACKGROUD COLOR chart.setBackgroundPaint(Color.getHSBColor(0.1f, 0.1f, 1.0f)); // Hue, saturation, brightness plot.setBackgroundPaint(manhattan_back); // Hue, saturation, brightness 9 // GRIDLINES plot.setDomainGridlineStroke(new BasicStroke(0.0f)); plot.setDomainMinorGridlineStroke(new BasicStroke(0.0f)); plot.setDomainGridlinePaint(manhattan_back.darker().darker()); // Hue, saturation, brightness 7 plot.setDomainMinorGridlinePaint(manhattan_back); // Hue, saturation, brightness 9 plot.setRangeGridlineStroke(new BasicStroke(0.0f)); plot.setRangeMinorGridlineStroke(new BasicStroke(0.0f)); plot.setRangeGridlinePaint(manhattan_back.darker().darker()); // Hue, saturation, brightness 7 plot.setRangeMinorGridlinePaint(manhattan_back.darker()); // Hue, saturation, brightness 8 plot.setDomainMinorGridlinesVisible(true); plot.setRangeMinorGridlinesVisible(true); // DOTS RENDERER XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, manhattan_dot); // renderer.setSeriesOutlinePaint(0, Color.DARK_GRAY); // renderer.setUseOutlinePaint(true); // Set dot shape of the currently appended Series renderer.setSeriesShape(0, new Rectangle2D.Double(0.0, 0.0, 2, 2)); renderer.setSeriesVisibleInLegend(0, false); NumberAxis positionAxis = (NumberAxis) plot.getDomainAxis(); // domainAxis.setAutoRangeIncludesZero(false); // domainAxis.setTickMarkInsideLength(2.0f); // domainAxis.setTickMarkOutsideLength(2.0f); // domainAxis.setMinorTickCount(2); // domainAxis.setMinorTickMarksVisible(true); positionAxis.setLabelAngle(1.0); positionAxis.setAutoRangeIncludesZero(false); positionAxis.setAxisLineVisible(true); positionAxis.setTickLabelsVisible(true); positionAxis.setTickMarksVisible(true); // ADD INVERSE LOG(10) Y AXIS LogAxis logPAxis = new LogAxis("P value"); logPAxis.setBase(10); logPAxis.setInverted(true); logPAxis.setNumberFormatOverride(GenericReportGenerator.FORMAT_P_VALUE); logPAxis.setTickMarkOutsideLength(2.0f); logPAxis.setMinorTickCount(2); logPAxis.setMinorTickMarksVisible(true); logPAxis.setAxisLineVisible(true); logPAxis.setUpperMargin(0); TickUnitSource units = NumberAxis.createIntegerTickUnits(); logPAxis.setStandardTickUnits(units); plot.setRangeAxis(0, logPAxis); // Add significance Threshold to subplot //threshold = 0.5/rdMatrixMetadata.getMarkerSetSize(); // (0.05/10? SNPs => 5*10-?) final Marker thresholdLine = new ValueMarker(threshold); thresholdLine.setPaint(Color.red); // Add legend to threshold thresholdLine.setLabel("P = " + GenericReportGenerator.FORMAT_P_VALUE.format(threshold)); thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT); thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); plot.addRangeMarker(thresholdLine); // Marker label if below threshold XYItemRenderer lblRenderer = plot.getRenderer(); // THRESHOLD AND SELECTED LABEL GENERATOR MySeriesItemLabelGenerator lblGenerator = new MySeriesItemLabelGenerator(threshold, chr); lblRenderer.setSeriesItemLabelGenerator(0, lblGenerator); lblRenderer.setSeriesItemLabelFont(0, new Font("SansSerif", Font.PLAIN, 12)); lblRenderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_LEFT, Math.PI / 4.0)); // TOOLTIP GENERATOR MyXYToolTipGenerator tooltipGenerator = new MyXYToolTipGenerator(chr); lblRenderer.setBaseToolTipGenerator(tooltipGenerator); lblRenderer.setSeriesItemLabelsVisible(0, true); return chart; }
From source file:edu.fullerton.viewerplugin.SpectrumPlot.java
private ChartPanel getPanel(ArrayList<ChanDataBuffer> dbufs, boolean compact) throws WebUtilException { ChartPanel ret = null;/* www . j a v a 2 s . c o m*/ try { float tfsMax = 0; for (ChanDataBuffer buf : dbufs) { ChanInfo ci = buf.getChanInfo(); float fs = ci.getRate(); tfsMax = Math.max(fs, tfsMax); } setFsMax(tfsMax); String gtitle = getTitle(dbufs, compact); int nbuf = dbufs.size(); XYSeries[] xys = new XYSeries[nbuf]; XYSeriesCollection mtds = new XYSeriesCollection(); int cnum = 0; compact = dbufs.size() > 2 ? false : compact; float bw = 1.f; for (ChanDataBuffer dbuf : dbufs) { String legend = getLegend(dbuf, compact); xys[cnum] = new XYSeries(legend); bw = calcSpectrum(xys[cnum], dbuf); mtds.addSeries(xys[cnum]); } DefaultXYDataset ds = new DefaultXYDataset(); String yLabel = pwrScale.toString(); DecimalFormat dform = new DecimalFormat("0.0###"); String xLabel; xLabel = String.format("Frequency Hz - (bw: %1$s, #fft: %2$,d, s/fft: %3$.2f, ov: %4$.2f)", dform.format(bw), nfft, secperfft, overlap); Double minx, miny, maxx, maxy; Double[] rng = new Double[4]; if (fmin <= 0) { fmin = bw; } float searchFmax = fmax; if (fmax <= 0 || fmax == Float.MAX_VALUE) { fmax = tfsMax / 2; searchFmax = tfsMax / 2 * 0.8f; } PluginSupport.getRangeLimits(mtds, rng, 2, fmin, searchFmax); minx = rng[0]; miny = rng[1]; maxx = rng[2]; maxy = rng[3]; findSmallest(mtds); int exp; if (maxy == 0. && miny == 0.) { miny = -1.; exp = 0; logYaxis = false; } else { miny = miny > 0 ? miny : smallestY; maxy = maxy > 0 ? maxy : miny * 10; exp = PluginSupport.scaleRange(mtds, miny, maxy); if (!logYaxis) { yLabel += " x 1e-" + Integer.toString(exp); } } JFreeChart chart = ChartFactory.createXYLineChart(gtitle, xLabel, yLabel, ds, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); if (logYaxis) { LogAxis rangeAxis = new LogAxis(yLabel); double smallest = miny * Math.pow(10, exp); rangeAxis.setSmallestValue(smallest); rangeAxis.setMinorTickCount(9); LogAxisNumberFormat lanf = new LogAxisNumberFormat(); lanf.setExp(exp); rangeAxis.setNumberFormatOverride(lanf); rangeAxis.setRange(smallest, maxy * Math.pow(10, exp)); rangeAxis.setStandardTickUnits(LogAxis.createLogTickUnits(Locale.US)); plot.setRangeAxis(rangeAxis); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.BLACK); } if (logXaxis) { LogAxis domainAxis = new LogAxis(xLabel); domainAxis.setBase(2); domainAxis.setMinorTickCount(9); domainAxis.setMinorTickMarksVisible(true); domainAxis.setSmallestValue(smallestX); domainAxis.setNumberFormatOverride(new LogAxisNumberFormat()); //domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setDomainAxis(domainAxis); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.BLACK); } ValueAxis domainAxis = plot.getDomainAxis(); if (fmin > Float.MIN_VALUE) { domainAxis.setLowerBound(fmin); } if (fmax != Float.MAX_VALUE) { domainAxis.setUpperBound(fmax); } plot.setDomainAxis(domainAxis); plot.setDataset(0, mtds); plot.setDomainGridlinePaint(Color.DARK_GRAY); plot.setRangeGridlinePaint(Color.DARK_GRAY); // Set the line thickness XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer(); BasicStroke str = new BasicStroke(lineThickness); int n = plot.getSeriesCount(); for (int i = 0; i < n; i++) { r.setSeriesStroke(i, str); } plot.setBackgroundPaint(Color.WHITE); if (compact) { chart.removeLegend(); } ret = new ChartPanel(chart); } catch (Exception ex) { throw new WebUtilException("Creating spectrum plot" + ex.getLocalizedMessage()); } return ret; }