Many histograms shown on a single canvas
Source code name: "histo_multi.py"
Programming language: Python
Topic: Plots/3D
DMelt Version 1. Last modified: 05/09/2015. License: Pro
https://datamelt.org/code/cache/histo_multi_3450.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.awt import Font,Color
from java.util import Random
from jhplot  import HPlot,H1D

# creade 2x3 plots
c1 = HPlot("Canvas",450,600,2,3)
# set global margins 
c1.setMarginSizeLeft(0.06);
c1.setMarginSizeRight(0.02);
c1.setMarginSizeBottom(0.05);
c1.setMarginSizeTop(0.06);

c1.setTextBottom("This is X");
c1.setTextLeft("This is Y");


c1.visible()
c1.setGTitle("Work with margins")
c1.setRangeAll(-3,3,0.0,50)
c1.setGridAll(0,0)
c1.setGridAll(1,0)


h1 = H1D("H1",20, -2.0, 2.0)
h2 = H1D("H2",20, -3.0, 3.0)
h3 = H1D("H3",20, -3.0, 3.0)
h4 = H1D("H4",20, -3.0, 3.0)
h5 = H1D("ANTIALIAS",30, -3.0, 3.0)


rand = Random()
# fill histogram
for i in range(700):
   h1.fill(rand.nextGaussian())
   h2.fill(2*rand.nextGaussian())
   h3.fill(3*rand.nextGaussian())
   h4.fill(4*rand.nextGaussian())
   h5.fill(1*rand.nextGaussian())
     

# set small gap between the graphs: 0
# to remove any gap, set to magic -3
Marg=-3

c1.cd(1,1)
h1.setFill(1)
h1.setFillColorTransparency(0.7)
h1.setFillColor(Color.red)
h2.setStyle("h")
c1.draw(h1)

# update margins
c1.setMarginBottom(Marg)
c1.setMarginRight(Marg)
c1.setTicLabels(0,0)
# avoid label overlaps
c1.setRange(-3,3,0.0001,50)
c1.update()


c1.cd(2,1)
h2.setStyle("p")
c1.draw(h2)
c1.setMarginBottom(Marg)
c1.setMarginLeft(Marg)
c1.setTicLabels(0,0)
c1.setTicLabels(1,0)
c1.update()


c1.cd(1,2)
h1.setColor(Color.blue)
c1.draw(h1)
# update margins
c1.setMarginBottom(Marg)
c1.setMarginTop(Marg)
c1.setMarginRight(Marg)
c1.setTicLabels(0,0)
 # avoid label overlaps
c1.setRange(-3,3,0.0001,99.9)
c1.update()



c1.cd(2,2)
h2.setColor(Color.green)
h2.setStyle("p")
c1.draw(h2)
c1.setMarginBottom(Marg)
c1.setMarginTop(Marg)
c1.setMarginLeft(Marg)
c1.setTicLabels(0,0)
c1.setTicLabels(1,0)
c1.update()


c1.cd(1,3)
h3.setStyle("pl")
c1.draw(h3)
c1.setMarginTop(Marg)
c1.setMarginRight(Marg)
# avoid label overlaps
c1.setRange(-3,2.99,0.0,49.99)
c1.update()


c1.cd(2,3)
c1.setAntiAlias(1)
h4.setStyle("l")
c1.draw(h5)
c1.setMarginTop(Marg)
c1.setMarginLeft(Marg)
c1.setTicLabels(1,0)
c1.setRange(-3,2.99,0.0,129.99)
c1.update()



# export to some image (png,eps,pdf,jpeg...)
# c1.export(Editor.DocMasterName()+".png");


You see the box below because you did not login.