Exemple #1
0
 def __init__(self, width, height, isTemporal=False):
     JPanel()
     self.isTemporal = isTemporal
     self.minY = 0.0  # -0.05
     self.minX = 0.0  # -0.02
     self.maxX = 0.5  # 0.52
     self.maxY = 1.0
     self.drawCI = False
     if isTemporal:
         self.title = "Fgt/Hs"
     else:
         self.title = "Fst/He"
     self.labelSelected = True
     self.labelNeutral = False
     self.posColor = Color.RED
     self.neuColor = Color.LIGHT_GRAY
     self.balColor = Color.YELLOW
     self.markerColor = Color.BLUE
     self.exportX = width
     self.exportY = height
     self.chart = self._createEmptyChart()
     self.chart.setAntiAlias(True)
     self.resetData()
     self.cp = ChartPanel(self.chart)
     self.cp.setDisplayToolTips(True)
     self.cp.setPreferredSize(Dimension(width, height))
     self.add(self.cp)
    def __init__(self, automations):

        # Create the frame
        frame = JFrame("Automation Viewer")
        frame.setSize(500, 300)
        frame.setLayout(BorderLayout())

        series = AutomationSeries
        # Finalize the window
        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)
        frame.setVisible(True)

        # Create an XY dataset
        dataset = XYSeriesCollection()

        for autoname in automations:

            automation = ModbusPal.getAutomation(autoname)
            series = AutomationSeries(automation)
            dataset.addSeries(series)
            frame.addWindowListener(series)

        # Create chart
        chart = ChartFactory.createXYLineChart("Automation Viewer",
                                               "Time (seconds)", "Value",
                                               dataset,
                                               PlotOrientation.VERTICAL,
                                               Boolean.TRUE, Boolean.TRUE,
                                               Boolean.FALSE)
        panel = ChartPanel(chart)

        # Add chart to panel
        frame.add(panel, BorderLayout.CENTER)
	def generatePlotPanel(self, plotTitle, listData, showLegend, showTooltip):
		"""
		1) Create a PieDataset
		2) Create a PieChart (or  Create a PiePlot and put it in a JFreeChart)
		3) Put the PieChart in a ChartPanel
		"""
		# Get a dictionary of value occurence in the list {value1:count, value2:count...}
		dataDico = Counter(listData)
		#print dataDico # value: counts OK
		 
		# Create a Pie dataset from the dicoData
		pieDataset = DefaultPieDataset() 
		for key, value in dataDico.items(): 
			#print key, value 
			pieDataset.setValue(key, value) 
				 
		# Create an instance of JFreeChart 	
		urls = False
		chart = ChartFactory.createPieChart(plotTitle, pieDataset, showLegend, showTooltip, urls) 
		
		# Alternative way
		#piePlot = PiePlot(pieDataset)
		#chart   = JFreeChart(plotTitle, piePlot)
		
		return ChartPanel(chart)
Exemple #4
0
    def __init__(self, width, height, range):
        JPanel()
        plot = MeterPlot(DefaultValueDataset(0))
        self.plot = plot
        self.setRange(range)
        #plot.addInterval(MeterInterval("Normal", Range(0.0, 35.0),
        #        Color.lightGray, BasicStroke(2.0),
        #        Color(0, 255, 0, 64)))
        #plot.addInterval(MeterInterval("Warning", Range(35.0, 50.0),
        #        Color.lightGray, BasicStroke(2.0), Color(255, 255, 0, 64)))
        #plot.addInterval(MeterInterval("Critical", Range(50.0, 60.0),
        #        Color.lightGray, BasicStroke(2.0),
        #        Color(255, 0, 0, 128)))
        plot.setNeedlePaint(Color.darkGray)
        plot.setDialBackgroundPaint(Color.white)
        plot.setDialOutlinePaint(Color.white)
        plot.setDialShape(DialShape.CHORD)
        plot.setMeterAngle(260)
        plot.setTickLabelsVisible(True)
        plot.setTickLabelFont(Font("Dialog", Font.BOLD, 10))
        plot.setTickLabelPaint(Color.darkGray)
        plot.setTickSize(5.0)
        plot.setTickPaint(Color.lightGray)

        plot.setValuePaint(Color.black)
        plot.setValueFont(Font("Dialog", Font.BOLD, 14))
        plot.setUnits("k sims")

        chart = JFreeChart("Simulations computed",
                           JFreeChart.DEFAULT_TITLE_FONT, plot, False)
        self.chart = chart
        chart.setBackgroundPaint(Color.white)
        cp = ChartPanel(chart)
        cp.setPreferredSize(Dimension(width, height))
        self.add(cp)
Exemple #5
0
    def show(self, size=(500, 500)):
        panel = ChartPanel(self.chart)

        def onclose(e):
            e.getWindow().dispose()
            self.dispose()

        frame = swing.JFrame(windowClosing=onclose)
        frame.setContentPane(panel)
        frame.size = size
        frame.visible = True
        self.frame = frame
Exemple #6
0
    def plot(self):
        chart = self.createChart()
        plot = chart.getXYPlot()
        if self.logx:
            logx = LogarithmicAxis("Log(" + xlabel() + ")")
            plot.setDomainAxis(logx)
        if self.logy:
            logy = LogarithmicAxis("Log(" + ylabel() + ")")
            plot.setRangeAxis(logy)

        chartPanel = ChartPanel(chart)
        chartPanel.setPreferredSize(
            java.awt.Dimension(self._size[0], self._size[1]))
        self.setContentPane(chartPanel)

        self.pack()
        self.setVisible(True)
Exemple #7
0
def plot(geoms, size=(500, 500)):
    """
  Plots a set of geometry objects into a xy grid.

  *geom* is a `list` of geometry objects to plot. *size* is the resulting
  size of the rendered plot.
  """

    if not isinstance(geoms, list):
        geoms = [geoms]

    gd = GeometryDataset(geoms)
    plot = gd.createPlot()
    chart = JFreeChart(plot)
    panel = ChartPanel(chart)

    frame = swing.JFrame()
    frame.setContentPane(panel)
    frame.size = size
    frame.visible = True
Exemple #8
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 generatePlotPanel(self, plotTitle, listData):
		"""
		1) Create a CategoryDataset
		2) Create a BarChart (or  Create a BarPlot and put it in a JFreeChart)
		3) Put the BarChart in a ChartPanel
		"""
		# Get a dictionary of value occurence in the list {value1:count, value2:count...}
		dataDico = Counter(listData)
		#print dataDico # value: counts OK
		 
		# Create a Pie dataset from the dicoData
		dataset = DefaultCategoryDataset() 
		for key, value in dataDico.items(): 
			#print key, value 
			dataset.setValue(value, key, "") 
		
		# Create an instance of JFreeChart 	
		chart = ChartFactory.createBarChart(plotTitle, "Categories", "Count", dataset) 
		# Alternative way
		#piePlot = PiePlot(pieDataset)
		#chart   = JFreeChart(plotTitle, piePlot)
		
		return ChartPanel(chart)
Exemple #10
0
def plot(geoms, size=(500,500)):
  """
  Plots a set of geometry objects into a xy grid.

  *geom* is a `list` of geometry objects to plot. *size* is the resulting
  size of the rendered plot.
  """

  if not isinstance(geoms, list):
    geoms = [geoms]

  data = GeometryDataset(geoms)
  r = GeometryRenderer()
  #r.setFillPolygons(True)

  plot = XYPlot(data, data.getDomain(), data.getRange(), r);
  chart = JFreeChart(plot)
  panel = ChartPanel(chart)
  
  frame = swing.JFrame()
  frame.setContentPane(panel)
  frame.size = size
  frame.visible = 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)