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) #print(ess) #print(vzr) # print(vmlnl) print("log marginal likelihood:", lnml)
from gram import Plot from data1 import xx1, yy1 gp = Plot() gp.baseName = 'line' gp.line(xx1, yy1) 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 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
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 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'
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 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()
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]) colorY = 16 gp.xYText(3, colorY, "color") gp.xYText(5, colorY, "-") gp.xYText(6, colorY, "+") gp.xYText(7, colorY, "-") gp.xYText(8, colorY, "+") fillY = 15 gp.xYText(3, fillY, "fill") gp.xYText(5, fillY, "-") gp.xYText(6, fillY, "-") gp.xYText(7, fillY, "+") gp.xYText(8, fillY, "+")
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 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_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()
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 gp.frameL = None gp.frameR = None 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("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()
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!