Customizing Histograms
Posted: Tue May 28, 2013 4:55 pm
Recently I have been working on running statistics using the libraries from McIDAS-V and Hydra in scripts. I needed to create histograms of the data. Since JFreeChart is packaged in the IDV/McIDAS-V external.jar file, I was able to use the JFreeChart API to create some simple histograms. The example below is done within McIDAS-V via the jython shell, but I have incorporated the technique in a script which is running in the background.
The result is
This is a partial tips and tricks. There are many options which I don't know how to use fully and other questions that I have. I hope that this can be expanded as I or others learn more.
Joleen
Code: Select all
import os
import java.io.File as File
import java.lang.Double as Double
import org.jfree.data.statistics as jfreeStats
import org.jfree.chart as jfreeCharts
homeDir=os.path.expanduser('~')
# get the data from the
a=selectData()
# some options for creating the histogram. Set to False.
show = 0;
toolTips = 0;
urls = 0;
# Initialize a dataset that can be used for creating histograms in JFreeChart
# The default type is HistogramType.FREQUENCY
newHD = jfreeStats.HistogramDataset()
# establish a low and high bin for the plot
lowBin = Double(180)
highBin = Double(360)
# Get the doubles array from the visad object captured with selectData()
myArray = (a[0].getValues())[0]
# add a series to the HistogramDataset object “newHD.” This will contain the array
# of doubles, 16 bins, and the low/high bins defined.
newHD.addSeries("H1",myArray,20, lowBin, highBin)
# create the histogram.
myHist=jfreeCharts.ChartFactory.createHistogram("My Title","3.9 micron Temperature (K)","Frequency",newHD,jfreeCharts.plot.PlotOrientation.VERTICAL,show,toolTips,urls)
# create a new java file object for saving the image
outFile = homeDir + "/testJFREE.png"
newFile = File(outFile)
#save the chart
jfreeCharts.ChartUtilities.saveChartAsPNG(newFile,myHist,600,600)
print "Done: saved as " + outFile
The result is
This is a partial tips and tricks. There are many options which I don't know how to use fully and other questions that I have. I hope that this can be expanded as I or others learn more.
Joleen