 |
Multiple objects and manually setting interactive keys with HKey
Source code name: "canvas2D_hkey_many.py"
Programming language: Python
Topic: Plots/2D
DMelt Version 1. Last modified: 05/09/2015. License: Pro
https://datamelt.org/code/cache/canvas2D_hkey_many_8638.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 *
from java.util import Random
from jhplot import *
# make empty canvas in some range
c1 =HPlot("Canvas")
c1.setGTitle("Testing data annotaions (HKey)")
c1.visible()
c1.setLegend(0)
c1.setAutoRange()
h1 = H1D("hist1",20, -2.0, 2.0)
h2 = H1D("hist2",10, -2.0, 2.0)
f1=F1D("50*x*x+100",-2,3)
p1= P1D("data1")
p1.setSymbol(5)
p1.setSymbolSize(10)
p1.setColor(Color.blue)
p2= P1D("data2")
p2.setColor(Color.red)
rand = Random()
for i in range(5000):
h1.fill(rand.nextGaussian())
h2.fill(1.0+rand.nextGaussian())
if (i<20): p1.add(-2+0.4*rand.nextGaussian(),300+30*rand.nextGaussian())
if (i<40): p2.add(-1.6+0.1*rand.nextGaussian(),500+30*rand.nextGaussian())
c1.draw(f1)
h1.setColor(Color(15,167,83))
h1.setPenWidth(2)
c1.draw(h1)
h2.setFill(1)
h2.setPenWidth(2)
h2.setFillColor(Color(122,20,157))
h2.setErrX(0)
h2.setErrY(1)
c1.draw(h2)
k=HKey("histo1",h1)
c1.add(k)
k=HKey("histo2",h2)
c1.add(k)
## now put a few points
c1.draw(p1)
c1.draw(p2)
k=HKey("data1",p1)
c1.add(k)
k=HKey("data2",p2)
c1.add(k)
k=HKey("10*x*x",f1)
c1.add(k)
# now show all objects
c1.update();
You see the box below because you did not login.