import math xx1 = [x/100. for x in range(-400, 401)] yy1a = [math.sqrt(1. + (x * x)) for x in xx1] yy1b = [-y for y in yy1a] from gram import Plot gp = Plot() g = gp.line(xx1, yy1a) g.colour = 'green' g = gp.line(xx1, yy1b) g.colour = 'green' g = gp.line(yy1a, xx1) g.colour = 'blue' g = gp.line(yy1b, xx1) g.color = 'blue' g = gp.line([-4, 4], [-4, 4]) g.color = 'red' g = gp.line([-4, 4], [4, -4]) g.colour = 'red' myTextSize = 'tiny' l1 = r'$y^2 + x^2 = 1$' g = gp.xYText(-2, 2.5, l1) g.anchor = 'west' g.textSize = myTextSize l1 = r'$x^2 - y^2 = 1$' g = gp.xYText(1.5, 1., l1) g.anchor = 'west'
from gram import Plot xx1 = [2.3, 3.5, 7.] yy1 = [3.3, 1.2, 5.6] xx2 = [-19.3, -14.3, -10.5] yy2 = [-2.6, -15.9, -9.3] gp = Plot() gp.baseName = 'plotArrayB' gp.line(xx1, yy1, smooth=True) gp.scatter(xx1, yy1) gp.yAxis.title = 'widgets' gp.xAxis.title = 'time (hours)' gp.minXToShow = 0.0 gp2 = Plot() gp2.line(xx2, yy2, smooth=False) gp2.scatter(xx2, yy2) gp2.yAxis.title = 'spin' gp2.yAxis.position = 'r' gp2.xAxis.title = 'impetus' gp2.gX = 4.3 gp2.gY = 0. gp.grams.append(gp2) gp.png() gp.svg() # smooth line plots do not work in svg
# Prepare the numbers, using p4.Numbers. Make the padMin and padMax # the same for both data, so that the histo lists are the same size. n1 = Numbers(nv1) n1.binSize = 1 n1.histo(verbose=False, padMin=-3, padMax=15.) n2 = Numbers(nv2) n2.binSize = 1 n2.histo(verbose=False, padMin=-3, padMax=15.) # prepare the binNames, and extract the histo values into separate # lists. binNames = [] vals1 = [] vals2 = [] for bNum in range(n1.nBins): binNames.append('%i' % int(n1.bins[bNum][0])) vals1.append(float(n1.bins[bNum][1])) vals2.append(float(n2.bins[bNum][1])) assert len(binNames) == len(vals1) assert len(vals1) == len(vals2) gp = Plot() gp.baseName = 'twoBarsA' gp.bars(binNames, [vals1, vals2]) gp.barValAxis.title = None gp.barNameAxis.title = None gp.png() gp.svg()
from gram import Plot read("data6.py") read("data6b.py") gp = Plot() gp.baseName = 'regression' gp.scatter(xx1, yy1, plotMark='square') g = gp.line(xx2, yy2, smooth=True) g.lineThickness = 'thick' gp.maxYToShow=100 gp.minXToShow=-2 gp.xAxis.title = None gp.yAxis.title = None gp.png() gp.svg()
import math from gram import Plot gp = Plot() gp.baseName = 'xyText' # make an invisible plot xx = range(17) yy = [math.sin(x) for x in xx] c = gp.line(xx, yy) c.colour = 'green' # make some text at x,y for i in range(len(xx)): c = gp.xYText(xx[i],yy[i],'%i' % i) c.shape = 'circle' c.fill = 'red!10' c.rotate = i * 15 gp.contentSizeX = 5. # remove the axes and frame gp.yAxis.title = None gp.xAxis.title = None gp.yAxis.styles.remove('ticks') gp.xAxis.styles.remove('ticks') gp.frameT = None gp.frameB = None gp.frameL = None gp.frameR = None gp.png() # gp.svg() # yuk!
import math from gram import Plot gp = Plot() gp.baseName = 'xyText' # make an invisible plot xx = list(range(17)) yy = [math.sin(x) for x in xx] c = gp.line(xx, yy) c.colour = 'green' # make some text at x,y for i in range(len(xx)): c = gp.xYText(xx[i],yy[i],'%i' % i) c.shape = 'circle' c.fill = 'red!10' c.rotate = i * 15 gp.contentSizeX = 5. # remove the axes and frame gp.yAxis.title = None gp.xAxis.title = None gp.yAxis.styles.remove('ticks') gp.xAxis.styles.remove('ticks') gp.frameT = None gp.frameB = None gp.frameL = None gp.frameR = None gp.png() gp.svg() # squares, not circles.
from gram import Plot read('data5.py') gp = Plot() gp.baseName = 'lineAndBar_good' c = gp.bars(binNames, binVals) gp.minBarValToShow = 0.0 gp.barNameAxis.title = None gp.barValAxis.title = 'frequency' c.barSets[0].fillColor = 'black!10' gp.barNameAxis.barLabelsEvery = 2 #gp.barNameAxis.textRotate = 90 gp.line(xx1, yy1, smooth=True) gp.xAxis.position = 't' gp.yAxis.position = 'r' gp.xAxis.title = None gp.yAxis.title = 'density' gp.maxXToShow = 4.0 gp.xAxis.tickLabelsEvery = 1 gp.maxBarValToShow = 5000 gp.maxYToShow = 1.0 gp.png() gp.svg()
print(f"{k:3}", end=' ') print(f"{bb[k]:12.6}", end=' ') print(f"{numpy.var(likes[k]):12.4f}", end=' ') print(f"{ess[k]:12.4f}", end=' ') print(f"{vzr[k]:12.8f}", end=' ') print(f"{zr[k]:12.6f}", end=' ') print(f"{vzr[k] / (zr[k] * zr[k]):14.6f}", end=' ') print() vmlnl = sum(vzr / (zr * zr)) lnml = sum(numpy.log(zr) + maxima) if args.gram: from gram import Plot gp = Plot() xx = list(bb[:-1]) yy = list(meanLogLikes) #gp.svgPxForCm = 100 gp.baseName = 'meanLogLikes' #gp.scatter(xx, yy) gp.line(xx, yy) gp.xAxis.title = r'$\beta_k$' gp.yAxis.title = 'mean log likelihood' gp.minXToShow = 0 gp.maxXToShow = 1 gp.pdf() #print(meanLogLikes) #print(maxima) #print(zr)
aa = list(range(1000)) for i in range(len(aa)): aa[i] /= 10. xx = [] yy = [] for i in range(len(aa)): a = aa[i] ret = func.polar2square([a, 1.]) xx.append(ret[0] + (i * 0.02)) yy.append(ret[1] + (i * 0.01) * (i * i * 0.001)) from gram import Plot gp = Plot() gp.baseName = 'circle' g = gp.line(xx, yy) g.color = 'red' gp.xAxis.title = None gp.yAxis.title = None gp.maxYToShow = 10000 gp.font = 'helvetica' gp.png() gp.svg()
from gram import Plot xx1 = [2,4,7,3,9] yy1 = [4,5,1,7,4] gp = Plot() gp.baseName = 'linesInPlot' gp.scatter(xx1, yy1, plotMark='diamond') gp.minXToShow = 0.0 g = gp.lineFromSlopeAndIntercept(1, 2) g.lineThickness = 'thick' gp.verticalLine(x=3, y=4) c = gp.verticalLine(8) c.colour = 'gray' c.lineThickness = 'very thick' gp.xAxis.title = None gp.yAxis.title = None gp.font = 'helvetica' gp.png() gp.svg()
aa = range(1000) for i in range(len(aa)): aa[i] /= 10. xx = [] yy = [] for i in range(len(aa)): a = aa[i] ret = func.polar2square([a, 1.]) xx.append(ret[0] + (i * 0.02)) yy.append(ret[1] + (i * 0.01) * (i * i * 0.001)) from gram import Plot gp = Plot() gp.baseName = 'circle' gp.line(xx, yy) gp.xAxis.title = None gp.yAxis.title = None gp.maxYToShow = 10000 gp.png() gp.svg()
from gram import Plot gp = Plot() gp.baseName = 'styles' gp.line([-1,3,6],[-2,5,0], smooth=True) # At this point, the styleDict is empty. # The styleDict is filled by render(). Calling # render() is usually automatic and hidden, # called by eg png(), but it can be called by # itself, and it does not hurt to call it # more than once. gp.render() st = gp.styleDict['tickLabel'] st.textFamily = 'ttfamily' st.textSize = 'large' st = gp.styleDict['axisLabel'] st.textFamily = 'ttfamily' st.textShape = 'itshape' st.textSize = 'huge' gp.xAxis.title = 'x' gp.yAxis.title = 'f(x)' gp.png() gp.svg()
from gram import Plot read("data2.py") gp = Plot() gp.font = 'helvetica' gp.baseName = 'barA' gp.bars(xx1, yy1) gp.png() gp.svg()
from gram import Plot read("data1.py") gp = Plot() gp.baseName = 'noFrame' gp.line(xx1, yy1) gp.yAxis.title = None gp.xAxis.title = None gp.yAxis.styles.remove('ticks') gp.xAxis.styles.remove('ticks') gp.frameT = None gp.frameB = None gp.frameL = None gp.frameR = None gp.font = 'helvetica' gp.png() gp.svg()
from gram import Plot xx1 = [2,4,7,3,9] yy1 = [4,5,1,7,4] gp = Plot() gp.contentSizeX = 2 gp.contentSizeY = 1.5 gp.baseName = 'textInPlot' gp.scatter(xx1, yy1, plotMark='asterisk') c = gp.xYText(7, 1.2, r'$\Downarrow$') c.anchor = 'south' c = gp.xYText(3.3, 7, r'$\leftarrow$\ Ignore this point') c.textSize = 'tiny' c.anchor = 'west' gp.xAxis.title = None gp.yAxis.title = None gp.png() # gp.svg() # looks bad, the latex text is not rendered
from gram import Plot xx1 = [2,4,7,3,9] yy1 = [4,5,1,7,4] gp = Plot() gp.baseName = 'linesInPlot' gp.scatter(xx1, yy1, plotMark='diamond') gp.minXToShow = 0.0 g = gp.lineFromSlopeAndIntercept(1, 2) g.lineThickness = 'thick' gp.verticalLine(x=3, y=4) c = gp.verticalLine(8) c.colour = 'gray' c.lineThickness = 'very thick' gp.xAxis.title = None gp.yAxis.title = None gp.png() gp.svg()
for rev in range(8): xx = [] yy = [] for i in range(len(rr)): r = rr[i] h = 0.0005 * j h += 0.5 j += 1 pt = func.polar2square([r, h]) xx.append(pt[0]) yy.append(pt[1]) xxx.append(xx) yyy.append(yy) from gram import Plot gp = Plot() gp.baseName = 'spiral' for rev in range(8): xx = xxx[rev] yy = yyy[rev] g = gp.line(xx, yy, smooth=True) g.lineStyle = gp.goodLineStyles[rev] print g.lineStyle gp.contentSizeX = 4.5 gp.contentSizeY = gp.contentSizeX gp.xAxis.title = None gp.yAxis.title = None gp.yAxis.styles.remove('ticks') gp.xAxis.styles.remove('ticks') gp.frameT = None gp.frameB = None
from gram import Plot execfile("data1.py") gp = Plot() gp.baseName = 'line' gp.line(xx1, yy1) gp.png() gp.svg()
for rev in range(8): xx = [] yy = [] for i in range(len(rr)): r = rr[i] h = 0.0005 * j h += 0.5 j += 1 pt = func.polar2square([r,h]) xx.append(pt[0]) yy.append(pt[1]) xxx.append(xx) yyy.append(yy) from gram import Plot gp = Plot() gp.baseName = 'spiral' for rev in range(8): xx = xxx[rev] yy = yyy[rev] g = gp.line(xx,yy,smooth=True) g.lineStyle = gp.goodLineStyles[rev] print(g.lineStyle) gp.contentSizeX = 4.5 gp.contentSizeY = gp.contentSizeX gp.xAxis.title = None gp.yAxis.title = None gp.yAxis.styles.remove('ticks') gp.xAxis.styles.remove('ticks') gp.frameT = None gp.frameB = None
from gram import Plot read('data5.py') gp = Plot() gp.baseName = 'lineAndBar_ugly' gp.bars(binNames,binVals) gp.line(xx1, yy1, smooth=True) gp.png() gp.svg()
from gram import Plot read("data2.py") gp = Plot() gp.baseName = 'barB' gp.font = 'helvetica' c = gp.bars(xx1, yy1) # c.barSets[0].fillColor = 'violet!20' gp.barValAxis.title = 'gnat infestations' gp.barNameAxis.title = None #gp.barValAxis.position = 'r' #gp.barNameAxis.position = 't' gp.minBarValToShow = 0. gp.maxBarValToShow = 80. gp.barNameAxis.textRotate = 44 # gp.png() gp.png() gp.svg()
import random from gram import Plot plotmarks = ['o', 'square', 'triangle', 'diamond'] gg = [] for i in [0,1]: for j in [0,1]: xx1 = [] yy1 = [] for k in range(23): xx1.append(random.random()) yy1.append(random.random()) gp = Plot() gp.contentSizeX = 2.5 gp.contentSizeY = 2. thePlotMark = plotmarks[(2 * i) +j] c = gp.scatter(xx1, yy1, plotMark=thePlotMark) gp.minXToShow = 0.0 gp.minYToShow = 0.0 gp.maxXToShow = 1.0 gp.maxYToShow = 1.0 theText = '[%i.%i]' % (i, j) c = gp.xYText(0.5, 0.5, theText) c.colour = 'blue' if i == 0: gp.xAxis.title = None gp.xAxis.styles.remove('ticks') else:
from gram import Plot gp = Plot() gp.baseName = 'styles' gp.line([-1, 3, 6], [-2, 5, 0], smooth=True) # At this point, the styleDict is empty. # The styleDict is filled by render(). Calling # render() is usually automatic and hidden, # called by eg png(), but it can be called by # itself, and it does not hurt to call it # more than once. gp.render() st = gp.styleDict['tickLabel'] st.textFamily = 'ttfamily' st.textSize = 'large' st = gp.styleDict['axisLabel'] st.textFamily = 'ttfamily' st.textShape = 'itshape' st.textSize = 'huge' gp.xAxis.title = 'x' gp.yAxis.title = 'f(x)' gp.png() gp.svg()
from gram import Plot read("data1.py") gp = Plot() gp.svgPxForCm = 100 gp.baseName = 'scatter' gp.scatter(xx1, yy1) gp.yAxis.title = 'scratches' gp.xAxis.title = 'itches' gp.minXToShow = 0 gp.maxXToShow = 12 gp.minYToShow = 0. gp.maxYToShow = 34 gp.png() gp.svg()
from gram import Plot read("data2.py") gp = Plot() gp.baseName = 'barA' gp.bars(xx1, yy1) gp.png() gp.svg()
from gram import Plot from data5 import xx1, yy1, binNames, binVals gp = Plot() gp.baseName = 'lineAndBar_good' c = gp.bars(binNames,binVals) gp.minBarValToShow = 0.0 gp.barNameAxis.title = None gp.barValAxis.title = 'frequency' c.barSets[0].fillColor = 'black!10' gp.barNameAxis.barLabelsEvery = 2 #gp.barNameAxis.textRotate = 90 gp.line(xx1, yy1, smooth=True) gp.xAxis.position = 't' gp.yAxis.position = 'r' gp.xAxis.title = None gp.yAxis.title = 'density' gp.maxXToShow = 4.0 gp.xAxis.tickLabelsEvery = 1 gp.maxBarValToShow = 5000 gp.maxYToShow = 1.0 gp.font = 'helvetica' gp.png() gp.svg()
from gram import Plot read('data5.py') gp = Plot() gp.baseName = 'lineAndBar_better' c = gp.bars(binNames, binVals) c.barSets[0].fillColor = 'black!10' gp.minBarValToShow = 0.0 gp.barNameAxis.title = None gp.barValAxis.title = 'frequency' gp.barNameAxis.barLabelsEvery = 2 gp.line(xx1, yy1, smooth=True) gp.xAxis.position = 't' gp.yAxis.position = 'r' gp.xAxis.title = None gp.xAxis.tickLabelsEvery = 2 gp.yAxis.title = 'density' gp.png() gp.svg() # line plot is not smooth
from gram import Plot markerShapes = ['+', 'x', '*', '-', '|', 'o', 'asterisk', 'square', 'square*', 'triangle', 'triangle*', 'diamond', 'diamond*'] gp = Plot() gp.baseName = 'plotMarks' for mShNum in range(len(markerShapes)): xx = [5] yy = [len(markerShapes) - mShNum] myMarker = markerShapes[mShNum] gp.scatter(xx, yy, plotMark=myMarker) g = gp.xYText(0, yy[0], myMarker) g.textFamily = 'ttfamily' g.anchor = 'west' xx = [6] g = gp.scatter(xx, yy, plotMark=myMarker) g.color = 'red' xx = [7] g = gp.scatter(xx, yy, plotMark=myMarker) g.fill = 'red' xx = [8] g = gp.scatter(xx, yy, plotMark=myMarker) g.color = 'blue' g.fill = 'yellow' gp.line([4.5,8.5], [14, 14])
from gram import Plot xx1 = [2, 4, 7, 3, 9] yy1 = [4, 5, 1, 7, 4] gp = Plot() gp.contentSizeX = 2 gp.contentSizeY = 1.5 gp.baseName = 'textInPlot' gp.scatter(xx1, yy1, plotMark='asterisk') c = gp.xYText(7, 1.2, r'$\Downarrow$') c.anchor = 'south' c = gp.xYText(3.3, 7, r'$\leftarrow$\ Ignore this point') c.textSize = 'tiny' c.anchor = 'west' gp.xAxis.title = None gp.yAxis.title = None gp.png() # gp.svg() # looks bad, the latex text is not rendered
from gram import Plot read("data2.py") gp = Plot() gp.baseName = 'barB' c = gp.bars(xx1, yy1) # c.barSets[0].fillColor = 'violet!20' gp.barValAxis.title = 'gnat infestations' gp.barNameAxis.title = None #gp.barValAxis.position = 'r' #gp.barNameAxis.position = 't' gp.minBarValToShow = 0. gp.maxBarValToShow = 80. gp.barNameAxis.textRotate = 44 # gp.png() gp.png() gp.svg()
# Prepare the numbers, using p4.Numbers. Make the padMin and padMax # the same for both data, so that the histo lists are the same size. n1 = Numbers(nv1) n1.binSize = 1 n1.histo(verbose=False,padMin=-3, padMax=15.) n2 = Numbers(nv2) n2.binSize = 1 n2.histo(verbose=False, padMin=-3, padMax=15.) # prepare the binNames, and extract the histo values into separate # lists. binNames = [] vals1 = [] vals2 = [] for bNum in range(n1.nBins): binNames.append('%i' % int(n1.bins[bNum][0])) vals1.append(float(n1.bins[bNum][1])) vals2.append(float(n2.bins[bNum][1])) assert len(binNames) == len(vals1) assert len(vals1) == len(vals2) gp = Plot() gp.baseName = 'twoBarsA' gp.bars(binNames, [vals1, vals2]) gp.barValAxis.title = None gp.barNameAxis.title = None gp.png() gp.svg()
n1.binSize = 1 n1.histo(verbose=False, padMin=-3, padMax=15.) n2 = Numbers(nv2) n2.binSize = 1 n2.histo(verbose=False, padMin=-3, padMax=15.) # prepare the binNames, and extract the histo values into separate # lists. binNames = [] vals1 = [] vals2 = [] for bNum in range(n1.nBins - 1): binNames.append('%i' % int(n1.bins[bNum][0])) vals1.append(float(n1.bins[bNum][1])) vals2.append(float(n2.bins[bNum][1])) assert len(binNames) == len(vals1) assert len(vals1) == len(vals2) gp = Plot() gp.baseName = 'twoBarsB' gp.bars(binNames, [vals1, vals2]) gp.barValAxis.title = None gp.barNameAxis.title = None gp.maxBarValToShow = 800. gp.barNameAxis.barLabelsEvery = 2 gp.barNameAxis.barLabelsSkipFirst = 1 gp.barNameAxis.textRotate = 90 gp.png() gp.svg()
from gram import Plot read('data5.py') gp = Plot() gp.baseName = 'lineAndBar_ugly' gp.bars(binNames, binVals) gp.line(xx1, yy1, smooth=True) gp.png() gp.svg()
from gram import Plot from data1 import xx1, yy1 gp = Plot() gp.baseName = 'line' gp.line(xx1, yy1) gp.png() gp.svg()
n1.binSize = 1 n1.histo(verbose=False,padMin=-3, padMax=15.) n2 = Numbers(nv2) n2.binSize = 1 n2.histo(verbose=False, padMin=-3, padMax=15.) # prepare the binNames, and extract the histo values into separate # lists. binNames = [] vals1 = [] vals2 = [] for bNum in range(n1.nBins - 1): binNames.append('%i' % int(n1.bins[bNum][0])) vals1.append(float(n1.bins[bNum][1])) vals2.append(float(n2.bins[bNum][1])) assert len(binNames) == len(vals1) assert len(vals1) == len(vals2) gp = Plot() gp.baseName = 'twoBarsB' gp.bars(binNames, [vals1, vals2]) gp.barValAxis.title = None gp.barNameAxis.title = None gp.maxBarValToShow = 800. gp.barNameAxis.barLabelsEvery = 2 gp.barNameAxis.barLabelsSkipFirst = 1 gp.barNameAxis.textRotate = 90 gp.png() gp.svg()
from gram import Plot read("data1.py") gp = Plot() gp.baseName = 'noFrame' gp.line(xx1, yy1) gp.yAxis.title = None gp.xAxis.title = None gp.yAxis.styles.remove('ticks') gp.xAxis.styles.remove('ticks') gp.frameT = None gp.frameB = None gp.frameL = None gp.frameR = None gp.png() gp.svg()
from gram import Plot from data5 import xx1, yy1, binNames, binVals gp = Plot() gp.baseName = 'lineAndBar_better' c = gp.bars(binNames,binVals) c.barSets[0].fillColor = 'black!10' gp.minBarValToShow = 0.0 gp.barNameAxis.title = None gp.barValAxis.title = 'frequency' gp.barNameAxis.barLabelsEvery = 2 gp.line(xx1, yy1, smooth=True) gp.xAxis.position = 't' gp.yAxis.position = 'r' gp.xAxis.title = None gp.xAxis.tickLabelsEvery = 2 gp.yAxis.title = 'density' gp.png() gp.font = 'helvetica' gp.svg() # line plot is not smooth