Example #1
0
def renderHistogram(values,
                    n_bins,
                    min_max=None,
                    title="Histogram",
                    color=Color.red,
                    show=True,
                    setThemeFn=setTheme):
    """ values: a list or array of numeric values.
      n_bins: the number of bins to use.
      min_max: defaults to None, a tuple with the minimum and maximum value.
      title: defaults to "Histogram", must be not None.
      show: defaults to True, showing the histogram in a new window.
      setThemeFn: defaults to setTheme, can be None or another function that takes a chart
               as argument and sets rendering colors etc.
      Returns a tuple of the JFreeChart instance and the window JFrame, if shown.
  """
    hd = HistogramDataset()
    hd.setType(HistogramType.RELATIVE_FREQUENCY)
    print min_max
    if min_max:
        hd.addSeries(title, values, n_bins, min_max[0], min_max[1])
    else:
        hd.addSeries(title, values, n_bins)
    chart = ChartFactory.createHistogram(title, "", "", hd,
                                         PlotOrientation.VERTICAL, False,
                                         False, False)
    # Adjust series color
    chart.getXYPlot().getRendererForDataset(hd).setSeriesPaint(0, color)
    #
    if setThemeFn:
        setThemeFn(chart)
    frame = None
    if show:
        frame = JFrame(title)
        frame.getContentPane().add(ChartPanel(chart))
        frame.pack()
        frame.setVisible(True)
    return chart, frame
def histogram(title, values):
    dataset = HistogramDataset()
    dataset.setType(HistogramType.RELATIVE_FREQUENCY)

    #NBINS = int(maths.sqrt(len(values)))
    #NBINS = int( (max(values)-min(values))/binW )
    NBINS = 64

    dataset.addSeries(title, values, NBINS)
    chart = ChartFactory.createHistogram(title, "Distance (nm)",
                                         "Relative Frequency", dataset,
                                         PlotOrientation.VERTICAL, False, True,
                                         False)
    plot = chart.getXYPlot()

    renderer = plot.getRenderer()
    renderer.setSeriesPaint(0, Colour.BLUE)
    painter = StandardXYBarPainter()
    renderer.setBarPainter(painter)
    frame = ChartFrame(title, chart)
    frame.setSize(1200, 800)
    frame.setLocationRelativeTo(None)
    frame.setVisible(True)
from ij import IJ
from org.jfree.chart import ChartFactory, ChartPanel
from org.jfree.data.statistics import HistogramDataset, HistogramType
from javax.swing import JFrame
from java.awt import Color

imp = IJ.getImage()
pixels = imp.getProcessor().convertToFloat().getPixels()

# Data and parameter of the histogram
values = list(pixels)
n_bins = 256 # number of histogram bins

# Construct the histogram from the pixel data
hist = HistogramDataset()
hist.setType(HistogramType.RELATIVE_FREQUENCY)
hist.addSeries("my data", values, n_bins)

# Create a JFreeChart histogram
chart = ChartFactory.createHistogram("My histogram", "the bins", "counts", hist)

# Adjust series color
chart.getXYPlot().getRendererForDataset(hist).setSeriesPaint(0, Color.blue)

# Show the histogram in an interactive window
# where the right-click menu enables saving to PNG or SVG, and adjusting properties
frame = JFrame("Histogram window")
frame.getContentPane().add(ChartPanel(chart))
frame.pack()
frame.setVisible(True)
Example #4
0
#--------------------Plot with jfreeChart environment-----------

values = xhistovector
bins = 20

dataset = HistogramDataset()
dataset.setType( HistogramType.FREQUENCY ) #other options: RELATIVE_FREQUENCY, SCALE_AREA_TO_1

dataset.addSeries( "Node count", values, bins)

chart = ChartFactory.createHistogram(
	"Node Count Histogram",
	"Bins",
	"Node count",
	dataset,
	PlotOrientation.VERTICAL,
	True,  # showLegend
	True,  # toolTips
	True,) # urls

# Save it as a PNG:
ChartUtilities.saveChartAsPNG(
  File("/Users/berthola/Desktop/Histotest/foo.png"),
  chart,
  800,
  600)

from org.jfree.chart import ChartPanel
from javax.swing import JFrame
from java.io import File
from java.awt import Dimension

values = [ random.randint(0,50) for x in xrange(1,100) ]
bins = 20

dataset = HistogramDataset()
dataset.setType( HistogramType.RELATIVE_FREQUENCY )

dataset.addSeries( "Random Stuff", values, bins)

chart = ChartFactory.createHistogram(
	"Example JFreeChart histogram",
	"This is the x axis",
	"This is the y axis",
	dataset,
	PlotOrientation.VERTICAL,
	True,  # showLegend
	True,  # toolTips
	True,) # urls

# Save it as a PNG:
ChartUtilities.saveChartAsPNG(
  File("/tmp/foo.png"),
  chart,
  800,
  600)

from org.jfree.chart import ChartPanel
from javax.swing import JFrame