Showing gaussian data as a histogram
Source code name: "xhart_histo_gauss.py"
Programming language: Python
Topic: Histograms/1D
DMelt Version 3. Last modified: 04/05/1977. License: Pro
https://datamelt.org/code/cache/xhart_histo_gauss_8998.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


from java.util import ArrayList,List,Random;
from org.knowm.xchart import CategoryChart
from org.knowm.xchart import CategoryChartBuilder
from org.knowm.xchart import Histogram
from org.knowm.xchart import SwingWrapper
from org.knowm.xchart.style.Styler import LegendPosition
from org.knowm.xchart import VectorGraphicsEncoder
from org.knowm.xchart.VectorGraphicsEncoder import VectorGraphicsFormat


chart = CategoryChartBuilder().width(800).height(600).title("Histogram").xAxisTitle("Mean").yAxisTitle("Count").build() 
chart.getStyler().setLegendPosition(LegendPosition.InsideNW);
chart.getStyler().setAvailableSpaceFill(.96);
chart.getStyler().setOverlapped(True);
chart.getStyler().setPlotGridVerticalLinesVisible(False);

def getGaussianData(count):
    data = ArrayList(count);
    r = Random();
    for i in range(count):
      data.add(r.nextGaussian() * 10);
    return data;

# Series
h1 =  Histogram(getGaussianData(10000), 20, -20, 20)
h2 =  Histogram(getGaussianData(5000), 20, -20, 20)
chart.addSeries("histogram 1", h1.getxAxisData(), h1.getyAxisData())
chart.addSeries("histogram 2", h2.getxAxisData(), h2.getyAxisData())

SwingWrapper(chart).displayChart()
VectorGraphicsEncoder.saveVectorGraphic(chart, "Histo", VectorGraphicsFormat.PDF);



You see the box below because you did not login.