List of usage examples for org.jfree.chart.axis LogAxis createLogTickUnits
public static TickUnitSource createLogTickUnits(Locale locale)
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//from w w w . j a va2s .c o m 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:edu.fullerton.viewerplugin.SpectrumPlot.java
private ChartPanel getPanel(ArrayList<ChanDataBuffer> dbufs, boolean compact) throws WebUtilException { ChartPanel ret = null;/*from ww w.j a va 2s. co 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; }