def plotIteration3D(data, mytitle, result_dir=None, xaxistitle="State Transition From 0 to 1", yaxistitle="State Transition From 0 to 1", mycolor=(0, 0, 0), minpoint=None, maxpoint=None): # Save the data into file try: fnameprefix = '-'.join(mytitle.split()) + '-3d' if result_dir: fnameprefix = os.path.join(result_dir, fnameprefix) datafile = fnameprefix + '.dat' with open(datafile, 'w') as f: f.write('\n'.join(['%s\t%s\t%s' % (x, y, z) for x, y, z in data])) f.close() print 'Data File written: %s' % datafile except: print '%s: Failed to save data file %s' % (mytitle, datafile) traceback.print_exc() try: g = graph.graphxyz(size=4, projector=graph.graphxyz.parallel(170, 45)) # g.plot(graph.data.file("color.dat", x=1, y=2, z=3, color=3), g.plot(graph.data.points(data, x=1, y=2, z=3, color=3), [ graph.style.surface(gradient=color.gradient.RedGreen, gridcolor=color.rgb.black, backcolor=color.rgb.black) ]) g.writePDFfile(fnameprefix) print 'Graph PDF File written: %s.pdf' % fnameprefix except: print '%s: Failed to create Graph' % mytitle traceback.print_exc()
def plotIteration3D(data, mytitle, result_dir=None, xaxistitle="State Transition From 0 to 1", yaxistitle="State Transition From 0 to 1", mycolor=(0,0,0), minpoint=None, maxpoint=None): # Save the data into file try: fnameprefix = '-'.join(mytitle.split()) + '-3d' if result_dir: fnameprefix = os.path.join(result_dir, fnameprefix) datafile = fnameprefix + '.dat' with open(datafile, 'w') as f: f.write('\n'.join(['%s\t%s\t%s' % (x,y,z) for x,y,z in data])) f.close() print 'Data File written: %s' % datafile except: print '%s: Failed to save data file %s' % (mytitle, datafile) traceback.print_exc() try: g = graph.graphxyz(size=4, projector=graph.graphxyz.parallel(170, 45)) # g.plot(graph.data.file("color.dat", x=1, y=2, z=3, color=3), g.plot(graph.data.points(data, x=1, y=2, z=3, color=3), [graph.style.surface(gradient=color.gradient.RedGreen, gridcolor=color.rgb.black, backcolor=color.rgb.black)]) g.writePDFfile(fnameprefix) print 'Graph PDF File written: %s.pdf' % fnameprefix except: print '%s: Failed to create Graph' % mytitle traceback.print_exc()
def main(): ''' Test code ''' print 'Passed import' print2d = False print3d = True if print2d: data = [(1, 1), (1.5, 1.7), (2.0, 3.0), (2.5, 2.5), (3.0, 2.0), (3.5, 1.5), (4.0, 0.5), (4.5, 0)] plot2d(data, 'Test-Data') if print3d: data = [ (0.44137052527, 0.544831665844, 0.0314080754412), (0.431536743272, 0.544398736017, 0.0318019973992), (0.419327149142, 0.543297793506, 0.0322310354077), (0.403113745823, 0.542323283885, 0.0328516649778), (0.38226652814, 0.541094026062, 0.0337153285836), (0.356440955193, 0.539137793051, 0.0348684146996), (0.325920056516, 0.535779200061, 0.0363212199381), (0.291858265482, 0.530117021477, 0.0380033504816), (0.256143473115, 0.521193379869, 0.0397474485233), (0.22091488599, 0.508331987432, 0.0413294839749), (0.188045554859, 0.491560787984, 0.0425442454526), (0.158705454016, 0.471845711496, 0.0432838933958), (0.133200978513, 0.450782646486, 0.0435615347829), ] try: fnameprefix = 'Test-Data3d' mytitle = 'Test Data 3D' g = graph.graphxyz(size=3) xdata = [x for x, y, z in data] ydata = [y for (x, y, z) in data] zdata = [z for (x, y, z) in data] g.plot(graph.data.file('TestData3d.dat'), [graph.style.surface()]) # g.plot(graph.data.points(data, x=1, y=2, z=3), # [graph.style.surface()]) # g = graph.graphxyz(size=4,projector=graph.graphxyz.parallel(170, 45)) # # g.plot(graph.data.file("color.dat", x=1, y=2, z=3, color=3), # g.plot(graph.data.points(data, x=1, y=2, z=3, color=3), # [graph.style.surface(gradient=color.gradient.RedGreen, # gridcolor=color.rgb.black, # backcolor=color.rgb.black)]) g.writeEPSfile(fnameprefix) g.writePDFfile(fnameprefix) print 'Graph PDF File written: %s.pdf' % fnameprefix except: print '%s: Failed to create Graph' % mytitle traceback.print_exc()
def main(): ''' Test code ''' print 'Passed import' print2d = False print3d = True if print2d: data = [(1,1), (1.5, 1.7), (2.0, 3.0), (2.5, 2.5), (3.0, 2.0), (3.5, 1.5), (4.0,0.5), (4.5,0)] plot2d(data, 'Test-Data') if print3d: data = [ (0.44137052527 , 0.544831665844, 0.0314080754412), (0.431536743272, 0.544398736017, 0.0318019973992), (0.419327149142, 0.543297793506, 0.0322310354077), (0.403113745823, 0.542323283885, 0.0328516649778), (0.38226652814 , 0.541094026062, 0.0337153285836), (0.356440955193, 0.539137793051, 0.0348684146996), (0.325920056516, 0.535779200061, 0.0363212199381), (0.291858265482, 0.530117021477, 0.0380033504816), (0.256143473115, 0.521193379869, 0.0397474485233), (0.22091488599 , 0.508331987432, 0.0413294839749), (0.188045554859, 0.491560787984, 0.0425442454526), (0.158705454016, 0.471845711496, 0.0432838933958), (0.133200978513, 0.450782646486, 0.0435615347829), ] try: fnameprefix = 'Test-Data3d' mytitle = 'Test Data 3D' g = graph.graphxyz(size=3) xdata = [x for x,y,z in data] ydata = [y for (x,y,z) in data] zdata = [z for (x,y,z) in data] g.plot(graph.data.file('TestData3d.dat'), [graph.style.surface()]) # g.plot(graph.data.points(data, x=1, y=2, z=3), # [graph.style.surface()]) # g = graph.graphxyz(size=4,projector=graph.graphxyz.parallel(170, 45)) # # g.plot(graph.data.file("color.dat", x=1, y=2, z=3, color=3), # g.plot(graph.data.points(data, x=1, y=2, z=3, color=3), # [graph.style.surface(gradient=color.gradient.RedGreen, # gridcolor=color.rgb.black, # backcolor=color.rgb.black)]) g.writeEPSfile(fnameprefix) g.writePDFfile(fnameprefix) print 'Graph PDF File written: %s.pdf' % fnameprefix except: print '%s: Failed to create Graph' % mytitle traceback.print_exc()
def make_alm_bg(bclc, begin_day_datetime, no_days, chart, obs, sun, sun_set, sun_rise) : ''' bclc: background clipped canvas''' # make a gradient of dark blue to black in the bg daycolor = color.rgb(0,82/255.0,137/255.0) nightcolor = color.rgb(0,0,0) DNcolgrad = color.lineargradient(daycolor,nightcolor) # First try: Drawing thick lines, does not really work. #for i in range(41) : # horangle = 18.0*i/40 # obs.horizon = '-%d' % (horangle) # eve_twi_grad = [] # mor_twi_grad = [] # for doy in range(no_days) : # obs.date = begin_day + doy # eve_twi_grad.append(obs.next_setting(sun)) # mor_twi_grad.append(obs.next_rising(sun)) # eve_twi_gradp = event_to_path(eve_twi_grad, chart) # mor_twi_gradp = event_to_path(mor_twi_grad, chart) # clc.stroke(eve_twi_gradp,[style.linewidth(0.24),DNcolgrad.getcolor(i/40.0)]) # clc.stroke(mor_twi_gradp,[style.linewidth(0.24),DNcolgrad.getcolor(i/40.0)]) ## Second try: using rectangles for each day. Leads to a very big file ## and artifacts on screen, especially with antialiasing, hopefully fine ## when printed. #def draw_LR_colgrad_rect(canv, LLx, LLy, W, H, colgrad, n) : # ''' Draw a rectangle consisting of n sub rectangles, each selecting its # color from the given color gradient.''' # for i in range(n) : # llx = (i+0.0)/n * W + LLx # lly = LLy # # XXX multiplication by 1.02 below is to make sure that # # XXX sub-rectangles overlap # w = 1.0/n * W * 1.02 # h = H # canv.fill(path.rect(llx, lly, w, h), [colgrad.getcolor((i+0.0)/n)]) # #day_thickness = chart.height/no_days #for doy in range(no_days) : # # XXX w/o the little addition of 0.2*ephem.hour below, we would have # # XXX small empty triangular regions. # SS = to_chart_coord(sun_set[doy]-0.2*ephem.hour, chart) # ET = to_chart_coord(eve_twilight[doy], chart) # MT = to_chart_coord(mor_twilight[doy], chart) # SR = to_chart_coord(sun_rise[doy]+0.2*ephem.hour, chart) ## evening twilight to darkness # LLx = SS[0] # LLy = SS[1] - day_thickness/2.0 # W = ET[0] - SS[0] # H = day_thickness # draw_LR_colgrad_rect(clc, LLx, LLy, W, H, DNcolgrad, 18) ## darkness to morning twilight # LLx = SR[0] # W = MT[0] - SR[0] # XXX note: negative width # draw_LR_colgrad_rect(clc, LLx, LLy, W, H, DNcolgrad, 18) ## Darkness between twilights #rev_eve_twilight = eve_twilight[:] #rev_eve_twilight.reverse() #darknesspath = event_to_path_no_check(rev_eve_twilight[:] + mor_twilight[:], chart) #darknesspath.append(path.closepath()) #clc.stroke(darknesspath, [nightcolor]) #clc.fill(darknesspath, [nightcolor]) # Third try: Per Alp Akoğlu's request let's try to this right. # This way it will also be more general and easier to adapt to higher # latitudes where twilight never ends on some days of the year. gdata = [] for doy in range(0, no_days, 10) : for tt in range(16*6+1) : # for 16 hours, every 10 minutes sun_tt = chart.ULcorn + doy + tt*ephem.minute*10 x, y = to_chart_coord(sun_tt, chart) obs.date = sun_tt sun.compute(obs) z = sun.alt/ephem.degrees('-18:00:00') if z>1 : z=1 if z<0 : z=0 z = z*z # this makes the twilight more prominent gdata.append([x, y, z]) # XXX I found the magic numbers below by trial error g = graph.graphxyz(size=1, xpos=11, ypos=16.73, xscale=12, yscale=18.31, projector=graph.graphxyz.parallel(-90, 90), x=graph.axis.linear(min=-1, max=chart.width+1, painter=None), #y=graph.axis.linear(min=-1, max=chart.height+1, painter=None), z=graph.axis.linear(min=-1, max=2, painter=None)) g.plot(graph.data.points(gdata, x=1, y=2, z=3, color=3), [graph.style.surface(gradient=DNcolgrad, gridcolor=None, backcolor=color.rgb.black)]) bclc.insert(g)