Article style with custom tick labels
Source code name: "style7.py"
Programming language: Python
Topic: Plots/2D
DMelt Version 1. Last modified: 05/09/2015. License: Pro
https://datamelt.org/code/cache/style7_1050.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.



import os,sys

from java.awt import *
from java.util import Random
from jhplot import * 
from jplot  import *


def applyStyleGray(c1,f1,h1,p1):

     style="Article style with custom tick labels"
     st = Font.BOLD + Font.ITALIC;
     f = Font("Serif",st,14);

     c1.setAntiAlias(True) 
     c1.setGTitle(style,f)    
     c1.setNameX("Time",Font("Serif", Font.ITALIC, 20))
     c1.setNameY("Values",Font("Serif", Font.ITALIC, 20))
     c1.setTicFont(Font("Serif", Font.ITALIC, 14)) 
     c1.setAxisPenTicWidth(1) 
     c1.setGridAll(0,True)
     c1.setGridAll(1,True)


     c1.setSubTicNumber(0,1) 
     c1.setSubTicNumber(1,2)
     c1.setTicsMirror(0,False) 
     c1.setTicsMirror(1,False)       
     c1.setTicLength(0,0.02)  
     c1.setTicLength(1,0.02)
     c1.setMarginLeft(70) 

     f1.setColor(Color.black)
     f1.setPenWidth(3)

     # apply style for histogram
     h1.setFill(1)
     h1.setPenWidth(2)
     h1.setErrX(0)
     h1.setErrY(1)
     h1.setFillColor( Color(0x787C80)  )


     # apply style for data points 
     p1.setSymbol(4)
     p1.setSymbolSize(6)
     p1.setColor( Color.black ) 
     return style 


# make empty canvas in some range
c1 =HPlot("Canvas")
c1.visible()
c1.setLegend(0)
c1.setRange(0,100,1,100)
c1.setMarginLeft(70)

h1 = H1D("Histogram",20, 50.0, 100.0)
f1=F1D("cos(x)*x",1,50)
f1.setPoints(5000) 
p1= P1D("X-Y data")

rand = Random(10)
for i in range(500):
      h1.fill(85+10*rand.nextGaussian())
      if (i<200): p1.add(56+7*rand.nextGaussian(),70+7*rand.nextGaussian())


# apply style 
style=applyStyleGray(c1,f1,h1,p1)
        

## now put a few points
c1.draw(f1)
c1.draw(h1)
c1.draw(p1)


# draw keys 
f=Font("Serif", Font.ITALIC, 14)
k=HKey(h1.getTitle(),0.25,0.8,f,Color.black,"NDC",h1 ) 
k.setKeySpace(-2) 
c1.add(k)

k=HKey(p1.getTitle(),0.25,0.75,f,Color.black,"NDC",p1 )                    
k.setKeySpace(2)
c1.add(k)

k=HKey(f1.getTitle(),0.25,0.7,f,Color.black,"NDC",f1 )
k.setKeySpace(-2)
c1.add(k)

# Tick replacement. Always do it after plotting objects, so you know 
# the default ticks
# after final update, extract ticks 
c1.setSubTicNumber(0,1) # reduce the number of subticks on X 
gs=c1.getGraphSettings()   # settings for this graph 
gs.setAutomaticTicks(0,False) # do not want to recompute ticks for manual settings 
listX=gs.getLabelTicks(0)     # obtain list of labels for ticks 
print "x=",listX
listX[0]="Jan"
listX[1]="Feb"
listX[2]="Mar"
listX[3]="Apr"
listX[4]="May"
listX[5]="Jun"
listX[6]="Jul"
listX[7]="Aug"
listX[8]="Sep"
listX[9]="Oct"
listX[10]="Nov"
gs.setLabelTicks(0,listX)
c1.update()


#import sys
#expfile=sys.argv[0].replace(".py",".png")
#c1.export(expfile)


You see the box below because you did not login.