def __init__(self,rows=None,cols=None,hgap=0.1,vgap=0.1, hoffset=(0.15,0.05),voffset=(0.05,0.15), width_to_height_ratio=1.0/0.7,multi_graphs=(), *args,**kwargs): Grace.__init__(self,*args,**kwargs) # add all of the keyword arguments as local attributes if len(multi_graphs)==0: multi_graphs = tuple(self.graphs) self._set_kwargs_attributes(locals()) # useful for obtaining a graph from a particular row or column self.graphs_rc = [] # used for fomatting multiple graphs self.frame_height = None # height of one graph self.frame_width = None # width of one graph # if rows and cols have been specified, add graphs to the # MultiGrace if self.rows is not None and self.cols is not None: for i in range(self.rows*self.cols): self.add_graph() self.multi(self.rows,self.cols,self.hoffset,self.voffset, self.hgap,self.vgap,self.width_to_height_ratio, multi_graphs)
def plot_array(data, labels=None, title="Title", xlabel="Array 1", ylabel="Array 2", graphtype="linxy", dirname="grace_sandbox/", pltname="testplot.agr", symbolsize=0., display=True): grace = Grace(colors=ColorBrewerScheme('Paired')) graph = grace.add_graph() graph.title.text = title graph.xaxis.label.text = xlabel graph.yaxis.label.text = ylabel if labels is not None: dsets = [graph.add_dataset(d, legend=l) for d, l in zip(data, labels)] else: dsets = [graph.add_dataset(d) for d in data] graph.set_different_colors() graph.set_different_symbols() for dset in dsets: dset.symbol.size=symbolsize #graph.set_world_to_limits() set_graphtype(graph, graphtype) graph.autoscale() outname = dirname+pltname grace.write_file(outname) if display: call(["xmgrace", outname])
def __init__(self, rows=None, cols=None, hgap=0.1, vgap=0.1, hoffset=(0.15, 0.05), voffset=(0.05, 0.15), width_to_height_ratio=1.0 / 0.7, multi_graphs=(), *args, **kwargs): Grace.__init__(self, *args, **kwargs) # add all of the keyword arguments as local attributes if len(multi_graphs) == 0: multi_graphs = tuple(self.graphs) self._set_kwargs_attributes(locals()) # useful for obtaining a graph from a particular row or column self.graphs_rc = [] # used for fomatting multiple graphs self.frame_height = None # height of one graph self.frame_width = None # width of one graph # if rows and cols have been specified, add graphs to the # MultiGrace if self.rows is not None and self.cols is not None: for i in range(self.rows * self.cols): self.add_graph() self.multi(self.rows, self.cols, self.hoffset, self.voffset, self.hgap, self.vgap, self.width_to_height_ratio, multi_graphs)
def __init__(self, data): grace = Grace() graph = grace.add_graph() graph.copy_format(ElGraph) graph.legend.loctype = "view" graph.legend.loc = (0.2, 0.4) define_graph(graph, "Sequence Identity Threshold", "Fraction of Curated Functions", 1.0, 0.0, 1.0, 0.0, 0.2, 0.2, 1, 1, 1, 1) grace.set_fonts('Helvetica') Data_Colors = { "Brassicaceae": 2, #Red "Eudicot": 11, #Orange "Liliopsida": 12, #Purple "Embryophyta": 15, #Green "Chlorophyta": 4 } #Blue for key in "Brassicaceae", "Eudicot", "Liliopsida", "Embryophyta", "Chlorophyta": Dataset = graph.add_dataset(data[key]) Dataset.line.color = Data_Colors[key] Dataset.symbol.fill_color = Data_Colors[key] Dataset.symbol.shape = 1 Dataset.symbol.color = 1 Dataset.legend = key self.grace = grace self.graph = graph pass
def histogram_plotting(datalist, path, filename, x_axis, y_axis): grace = Grace(colors=ColorBrewerScheme('Paired')) graph = grace.add_graph() graph.set_labels(str(x_axis), str(y_axis)) dataset1 = graph.add_dataset(datalist) dataset1.line.type = 0 dataset1.line.color = 7 dataset1.line.linewidth = 4.0 dataset1.symbol.fill_color = 'white' dataset1.symbol.shape = 1 graph.legend.box_color = 0 graph.legend.char_size = 0.85 graph.legend.loc = (0.55, 0.80) xmin, ymin, xmax, ymax = graph.get_world() graph.set_world(0, 0.001, 200, 1000) graph.yaxis.set_log() graph.autoscalex() graph.xaxis.set_format('decimal', 0) grace.write_file(str(path) + str(filename) + '_histogram_points.agr')
def from_axis(ax, data, labels=None, graphtype="linxy", dirname="grace_sandbox/", pltname="testplot.agr", symbolsize=0., display=True): grace = Grace(colors=ColorBrewerScheme('Paired')) graph = grace.add_graph() title = str(ax.get_title()) xlabel = str(ax.get_xlabel()) ylabel = str(ax.get_ylabel()) plot_array(data, labels=labels, title=title, xlabel=xlabel, ylabel=ylabel, graphtype=graphtype, pltname=pltname, symbolsize=symbolsize, display=display)
def scatterplot(x_points, y_points, xTitle, yTitle, graphTitle, subTitle, filename): grace = Grace() graph = grace.add_graph() graph.title.text = graphTitle graph.title.size = .9 graph.subtitle.text = subTitle graph.subtitle.size = .7 graph.xaxis.label.text = xTitle graph.xaxis.label.char_size = 1.5 graph.xaxis.ticklabel.format = 'Decimal' graph.xaxis.ticklabel.char_size = 1 graph.xaxis.ticklabel.prec = 2 graph.yaxis.label.text = yTitle graph.yaxis.label.char_size = 1.5 graph.yaxis.ticklabel.char_size = 1 graph.yaxis.ticklabel.format = 'Decimal' graph.yaxis.ticklabel.prec = 2 points = graph.add_dataset(zip(x_points, y_points)) points.symbol.shape = 1 points.symbol.color = 2 # perimeter of the symbol points.symbol.fill_color = 2 # inside the symbol points.line.color = 0 #NO LINE grace.autoscale() grace.write_file(filename)
def linegraph(x, y, xTitle, yTitle, title, subtitle, filename): data = zip(x, y) grace = Grace() graph = grace.add_graph() graph.xaxis.label.text = xTitle graph.xaxis.label.char_size = 1.5 graph.xaxis.ticklabel.format = 'Decimal' graph.xaxis.ticklabel.char_size = 1 graph.xaxis.ticklabel.prec = 0 graph.yaxis.label.text = yTitle graph.yaxis.label.char_size = 1.5 graph.yaxis.ticklabel.char_size = 1 graph.yaxis.ticklabel.format = 'Decimal' graph.yaxis.ticklabel.prec = 0 graph.title.text = title graph.title.size = .9 graph.subtitle.text = subtitle graph.subtitle.size = .7 dataset1 = graph.add_dataset(data) dataset1.symbol.shape = 1 # 0: no symbol dataset1.symbol.color = 2 dataset1.symbol.fill_color = 2 dataset1.symbol.size = 1 dataset1.line.color = 2 graph.legend.box_linestyle = 0 # NO legend box grace.autoscale() grace.write_file(filename)
def multilinegraph(x,ys,xTitle,yTitle,yLabel,graphTitle,subtitle,filename): #ys is a list of y-series grace = Grace() graph = grace.add_graph() graph.title.text = graphTitle graph.title.size = .8 graph.subtitle.text = subtitle graph.subtitle.size = .6 graph.xaxis.label.text = xTitle graph.xaxis.label.char_size = 1 graph.xaxis.ticklabel.format = 'Decimal' graph.xaxis.ticklabel.char_size = .8 graph.xaxis.ticklabel.prec = 2 graph.yaxis.label.text = yTitle graph.yaxis.label.char_size = 1 graph.yaxis.ticklabel.char_size = .8 graph.yaxis.ticklabel.format = 'Decimal' graph.yaxis.ticklabel.prec = 2 for [i,y] in enumerate(ys): dataset = graph.add_dataset(zip(x,y),legend=yLabel[i]) dataset.symbol.shape = 0 dataset.line.color = 1 grace.autoscale() grace.write_file(filename)
def loglogpointgraph(x_points,y_points,xTitle,yTitle,graphTitle,subTitle,filename): grace = Grace() graph = grace.add_graph() graph.title.text = graphTitle graph.title.size = .8 graph.subtitle.text = subTitle graph.subtitle.size = .6 graph.xaxis.label.text = xTitle graph.xaxis.label.char_size = 1 graph.xaxis.ticklabel.format = 'Decimal' graph.xaxis.ticklabel.char_size = .8 graph.xaxis.ticklabel.prec = 2 graph.xaxis.scale = 'Logarithmic' graph.yaxis.label.text = yTitle graph.yaxis.label.char_size = 1 graph.yaxis.ticklabel.char_size = .8 graph.yaxis.ticklabel.format = 'Decimal' graph.yaxis.ticklabel.prec = 2 graph.yaxis.scale = 'Logarithmic' points = graph.add_dataset(zip(x_points,y_points)) points.symbol.shape = 1 points.line.color = 0 grace.autoscale() grace.write_file(filename)
def pointlinegraph(x_points,y_points,x,y,xTitle,yTitle,graphTitle,graphSubtitle,filename): #I think this adds datasets in the reverse order that I want? Fix me! grace = Grace() graph = grace.add_graph() graph.title.text = graphTitle graph.title.size = .8 graph.subtitle.text = graphSubtitle graph.subtitle.size = .6 graph.xaxis.label.text = xTitle graph.xaxis.label.char_size = 1 graph.xaxis.ticklabel.format = 'Decimal' graph.xaxis.ticklabel.char_size = .8 graph.xaxis.ticklabel.prec = 2 graph.yaxis.label.text = yTitle graph.yaxis.label.char_size = 1 graph.yaxis.ticklabel.char_size = .8 graph.yaxis.ticklabel.format = 'Decimal' graph.yaxis.ticklabel.prec = 2 points = graph.add_dataset(zip(x_points,y_points)) points.symbol.shape = 3 points.line.type = 0 line = graph.add_dataset(zip(x,y)) line.symbol.shape = 0 line.line.color = 1 grace.autoscale() grace.write_file(filename)
def bargraph(x,y,xTitle,yTitle,title,subtitle,filename): data = zip(x,y) grace = Grace() graph = grace.add_graph() graph.xaxis.label.text = xTitle graph.xaxis.label.char_size = .9 graph.xaxis.ticklabel.format = 'Decimal' graph.xaxis.ticklabel.char_size = .7 graph.xaxis.ticklabel.prec = 0 graph.yaxis.label.text = yTitle graph.yaxis.label.char_size = .9 graph.yaxis.ticklabel.char_size = .7 graph.yaxis.ticklabel.format = 'Decimal' graph.yaxis.ticklabel.prec = 0 graph.title.text = title graph.title.size = 1 graph.subtitle.text = subtitle graph.subtitle.size = .8 dataset1 = graph.add_dataset(data,type = 'bar') dataset1.symbol.shape = 0 dataset1.line.type = 0 grace.autoscale() grace.write_file(filename)
def linegraphwpts(x,y,xTitle,yTitle,title,subtitle,filename): data = zip(x,y) grace = Grace() graph = grace.add_graph() graph.xaxis.label.text = xTitle graph.xaxis.label.char_size = .8 graph.xaxis.ticklabel.format = 'Decimal' graph.xaxis.ticklabel.char_size = .8 graph.xaxis.ticklabel.prec = 0 graph.yaxis.label.text = yTitle graph.yaxis.label.char_size = .8 graph.yaxis.ticklabel.char_size = .8 graph.yaxis.ticklabel.format = 'Decimal' graph.yaxis.ticklabel.prec = 0 graph.title.text = title graph.title.size = 1.2 graph.subtitle.text = subtitle graph.subtitle.size = .7 dataset1 = graph.add_dataset(data) dataset1.symbol.shape = 1 dataset1.symbol.size = 1.1 grace.autoscale() grace.write_file(filename)
def linegraph(x, y, xTitle, yTitle, title, subtitle, filename): data = zip(x, y) grace = Grace() graph = grace.add_graph() graph.xaxis.label.text = xTitle graph.xaxis.label.char_size = 2 graph.xaxis.ticklabel.format = 'Decimal' graph.xaxis.ticklabel.char_size = 2 graph.xaxis.ticklabel.prec = 0 # graph.world.ymin=0 # i set the x and y range i am plotting #graph.world.ymax=20 # i set the x and y range i am plotting #graph.yaxis.tick.major_size=2 graph.yaxis.label.text = yTitle graph.yaxis.label.char_size = 2 graph.yaxis.ticklabel.char_size = 2 graph.yaxis.ticklabel.format = 'Decimal' graph.yaxis.ticklabel.prec = 0 graph.title.text = title graph.title.size = .9 graph.subtitle.text = subtitle graph.subtitle.size = .7 dataset1 = graph.add_dataset(data) dataset1.symbol.shape = 0 dataset1.line.color = 1 graph.legend.box_linestyle = 0 # NO legend box grace.autoscale() #comment this if i wanna set my own xy ranges. grace.write_file(filename)
def realmultilinegraph(xs,ys,xTitle,yTitle,list_yLegends,filename, colors): #ys is a list of y-series #xs is a list of x-series #1:black #2:red #3: light green #4:dark blue #5:yellow #6:light brown #7:grey #8:purple #9:cyan #10:pink #11:orange #12: purple2 #13:maroon #14:cyan2 #15:dark green grace = Grace() graph = grace.add_graph() # graph.title.text = graphTitle graph.title.size = 1.2 #graph.subtitle.text = subtitle graph.subtitle.size = .6 graph.xaxis.label.text = xTitle graph.xaxis.label.char_size = 2 graph.xaxis.ticklabel.format = 'Decimal' graph.xaxis.ticklabel.char_size = 2 graph.xaxis.ticklabel.prec = 2 graph.yaxis.label.text = yTitle graph.yaxis.label.char_size = 2 graph.yaxis.ticklabel.char_size = 2 graph.yaxis.ticklabel.format = 'Decimal' graph.yaxis.ticklabel.prec = 2 graph.yaxis.tick.minor_size = 0 for [i,y] in enumerate(ys): dataset = graph.add_dataset(zip(xs[i],y),legend=list_yLegends[i]) dataset.symbol.shape = 0 # dataset.symbol.size = 0.5 # dataset.symbol.color = colors[i] # dataset.symbol.fill_color = colors[i] dataset.line.color = colors[i] graph.legend.char_size = 1. graph.legend.loc = (.21,.8) graph.legend.box_linestyle=0 # NO legend box grace.autoscale() grace.write_file(filename)
def realmultilinegraph(xs, ys, xTitle, yTitle, list_yLegends, filename, colors): #ys is a list of y-series #1:black #2:red #3: light green #4:dark blue #5:yellow #6:light brown #7:grey #8:purple #9:cyan #10:pink #11:orange #12: purple2 #13:maroon #14:cyan2 #15:dark green grace = Grace() graph = grace.add_graph() # obj1 = grace.add_drawing_object(DrawText) # graph.title.text = graphTitle graph.title.size = 1.2 #graph.subtitle.text = subtitle graph.subtitle.size = .6 graph.xaxis.label.text = xTitle graph.xaxis.label.char_size = 2 graph.xaxis.ticklabel.format = 'Decimal' graph.xaxis.ticklabel.char_size = 2 graph.xaxis.ticklabel.prec = 2 graph.yaxis.label.text = yTitle graph.yaxis.label.char_size = 2 graph.yaxis.ticklabel.char_size = 2 graph.yaxis.ticklabel.format = 'Decimal' graph.yaxis.ticklabel.prec = 2 # file order: high_95_conf_interv, low_95_conf_interv, empirical, model cont = 0 for [i, y] in enumerate(ys): dataset = graph.add_dataset(zip(xs[i], y), legend=list_yLegends[i]) dataset.symbol.shape = 0 dataset.line.linewidth = 3 dataset.line.color = colors[i] cont += 1 graph.legend.char_size = 1. graph.legend.loc = (.2, .81) graph.legend.box_linestyle = 0 # NO legend box grace.autoscale() grace.write_file(filename)
def _dist_formatting(self): Dir = "./Blog_comments_network/plots/" self.filename= "distribution_of_number_of_blog_com_on_each_blog" data = self.data grace = Grace(colors=ColorBrewerScheme('Paired')) graph = grace.add_graph() graph.set_labels("posts (n)", "P(N>=n)") dataset1 = graph.add_dataset(data) dataset1.line.type = 0 dataset1.line.color = 1 dataset1.line.linewidth = 4.0 dataset1.symbol.fill_color = 'white' dataset1.symbol.shape = 1 dataset1.symbol.size = 0.7 dataset1.symbol.color = 1 dataset1.symbol.color = 'black' graph.legend.box_color = 0 graph.legend.char_size = 0.85 graph.legend.loc = (0.55,0.80) graph.yaxis.set_log() graph.xaxis.set_log() #graph.autoscaley() #graph.autoscalex() xmin,xmax,ymin,ymax = 0.80,10000,0.00001,1 graph.set_world(xmin,ymin,xmax,ymax) graph.xaxis.set_format('decimal',0) graph.title.text = str(self.filename) graph.subtitle.text = ("average="+str(self.avg_posts)+"std="+str(self.std_posts)) graph.title.size = 1.2 graph.subtitle.size = 0.8 grace.write_file(Dir+str(self.filename)+'.agr')
def cdf_plotting(self): Dir = self.Dir data = self.plotdata grace = Grace(colors=ColorBrewerScheme('Paired')) graph = grace.add_graph() graph.set_labels(str(self.x_axis), (self.y_axis)) dataset1 = graph.add_dataset(data) dataset1.line.type = 0 dataset1.line.color = 1 dataset1.line.linewidth = 4.0 dataset1.symbol.fill_color = 'white' dataset1.symbol.shape = 1 dataset1.symbol.size = 0.7 dataset1.symbol.color = 1 dataset1.symbol.color = 'black' graph.legend.box_color = 0 graph.legend.char_size = 0.85 graph.legend.loc = (0.55, 0.80) graph.autoscaley() graph.xaxis.set_log() #graph.autoscaley() #graph.autoscalex() xmin, xmax, ymin, ymax = 0.80, 10000, 0.00001, 1 graph.set_world(xmin, ymin, xmax, ymax) graph.xaxis.set_format('decimal', 0) graph.title.text = str(self.filename) graph.title.size = 1.2 graph.subtitle.size = 1.2 grace.write_file(Dir + str(self.filename) + '.agr')
def PlotCDF(datat, dataf,title=''): grace = Grace() graph = grace.add_graph() graph.xaxis.label.text = 'Score' graph.yaxis.label.text = 'CDF' graph.title.text= title graph.xaxis.ticklabel.format='decimal' graph.xaxis.ticklabel.prec=2 # graph.xaxis.tick.major = 4 # graph.xaxis.tick.minor_ticks = 0 dataset = graph.add_dataset(datat)#), legend=country) dataset.symbol.shape = 0 dataset.line.type = 3 dataset.line.color=1 dataset = graph.add_dataset(dataf)#), legend=country) dataset.symbol.shape = 0 dataset.line.type = 3 dataset.line.color=2 graph.set_world_to_limits() grace.write_file(title+'.agr')
def sectionedbargraph(ys,xTitle,yTitle,yLabel,title,subtitle,filename): grace = Grace() graph = grace.add_graph() graph.xaxis.label.text = xTitle graph.xaxis.label.char_size = .8 graph.xaxis.ticklabel.char_size = .8 graph.xaxis.ticklabel.format = 'Decimal' graph.xaxis.ticklabel.prec = 0 graph.yaxis.label.text = yTitle graph.yaxis.label.char_size = .8 graph.yaxis.ticklabel.char_size = .8 graph.yaxis.ticklabel.format = 'Decimal' graph.yaxis.ticklabel.prec = 0 graph.title.text = title graph.title.size = .9 graph.subtitle.text = subtitle graph.subtitle.size = .7 base = 0 for [i,y] in enumerate(ys): ylen = len(y) x = range(base, base + ylen) base += ylen - 1 dataset = graph.add_dataset(zip(x,y), type = 'bar', legend=yLabel[i]) dataset.line.type = 0 dataset.symbol.color = colors[i] dataset.symbol.fill_color = colors[i] dataset.symbol.size = .2 graph.legend.char_size = .6 graph.legend.loc = (.8,.75) grace.autoscale() grace.write_file(filename)
def realmultilinegraph_log(xs, ys, xTitle, yTitle, yLabel, graphTitle, subtitle, filename): #ys is a list of y-series grace = Grace() graph = grace.add_graph() graph.title.text = graphTitle graph.title.size = .8 graph.subtitle.text = subtitle graph.subtitle.size = .6 graph.xaxis.label.text = xTitle graph.xaxis.label.char_size = .8 graph.xaxis.ticklabel.format = 'Scientific' graph.xaxis.ticklabel.char_size = .6 graph.xaxis.ticklabel.prec = 2 graph.xaxis.scale = 'Logarithmic' graph.yaxis.label.text = yTitle graph.yaxis.label.char_size = .8 graph.yaxis.ticklabel.char_size = .6 graph.yaxis.ticklabel.format = 'Scientific' graph.yaxis.ticklabel.prec = 2 graph.yaxis.scale = 'Logarithmic' for [i, y] in enumerate(ys): dataset = graph.add_dataset(zip(xs[i], y), legend=yLabel[i]) dataset.symbol.shape = 3 dataset.line.color = colors[i] dataset.symbol.color = colors[i] dataset.symbol.fill_color = colors[i] graph.legend.char_size = .6 graph.legend.loc = (.2, .75) grace.autoscale() grace.write_file(filename)
from PyGrace.grace import Grace from PyGrace.colors import ColorBrewerScheme from PyGrace.drawing_objects import DrawText # ---------------------------------- this is the part where YOU do the analysis # all datasets are lists of (x, y) points import example_tools data1, data2, data3, data4, data5 = example_tools.multiplot() # make a Grace instance with the "Set1" color scheme grace = Grace(colors=ColorBrewerScheme('Set1')) # this function returns the maximum x and y "view" values to fit in the page xView, yView = grace.set_landscape() # create graphs and set locations on page graph1 = grace.add_graph() graph1.set_view(0.10 * xView, 0.55 * yView, 0.90 * xView, 0.90 * yView) # to illustrate the use of drawing objects, and just to make things a little # more complicated, here is a manually added label to graph 1. title1 = graph1.add_drawing_object(DrawText, text='(a) Regression', x=0.10*xView, y=0.91*yView, just=4) # this will set the axis labels. it is a good idea to use raw strings (r'') # so that backslashes (which are used to give xmgrace text formatting commands) # are not used as escape characters. graph1.set_labels(r'\xt\4', r'\xg\4(\xt\4)') graph2 = grace.add_graph() graph2.set_view(0.10 * xView, 0.10 * yView, 0.45 * xView, 0.45 * yView)
import sys sys.path.append('../../') sys.path.append('../') from PyGrace.grace import Grace from PyGrace.Styles.el import * # the purpose of this example is to illustrate how to use different # grace styles rather than manipulating the standard grace styles all # the time # instantiate a grace object grace = Grace() # add a graph graph = grace.add_graph(ElEmptySquareGraph) # add some data sets dx = 0.01 data = [(i*dx,i*dx*i*dx+1) for i in range(int(-1/dx),int(1/dx)+1)] dataset = graph.add_dataset(data,ElShadedDataSet,7) dataset.line.configure(color=1,linewidth=2.0,linestyle=1) data = [(i*dx,2*i*dx*i*dx) for i in range(int(-1/dx),int(1/dx)+1)] dataset = graph.add_dataset(data,ElShadedDataSet,0) dataset.line.configure(color=1,linewidth=2.0,linestyle=1) data = [(-0.5,1.75),(0.5,1.75)] dataset = graph.add_dataset(data,ElCircleDataSet,7) dataset.symbol.size = 3.0 dataset.symbol.linestyle = 0
def realmultilinegraph(xs,ys,xTitle,yTitle,list_yLegends,filename, colors): #ys is a list of y-series #xs is a list of x-series #1:black #2:red #3: light green #4:dark blue #5:yellow #6:light brown #7:grey #8:purple #9:cyan #10:pink #11:orange #12: purple2 #13:maroon #14:cyan2 #15:dark green grace = Grace() graph = grace.add_graph() # obj1 = grace.add_drawing_object(DrawText) # graph.title.text = graphTitle graph.title.size = 1.2 #graph.subtitle.text = subtitle graph.subtitle.size = .6 graph.xaxis.label.text = xTitle graph.xaxis.label.char_size = 2 graph.xaxis.ticklabel.format = 'Decimal' graph.xaxis.ticklabel.char_size = 2 graph.xaxis.ticklabel.prec = 2 graph.yaxis.label.text = yTitle graph.yaxis.label.char_size = 2 graph.yaxis.ticklabel.char_size = 2 graph.yaxis.ticklabel.format = 'Decimal' graph.yaxis.ticklabel.prec = 2 # filename order: background, empirical, filename_model_I_train,filename_model_I_test,filename_model_P_train,filename_model_P_test cont=0 for [i,y] in enumerate(ys): # enumerate([j,u,l,i,a]) returs a list of tuples: [(0,j),(1,u),(2,l),(3,i),(4,a)] # zip([a,b,c],[1,2,3]) returns [(a,1),(b,2),(c,3)] dataset = graph.add_dataset(zip(xs[i],y),legend=list_yLegends[i]) dataset.symbol.shape = 0 if cont==0: # the fist dataset is just fake data for the background dataset.fill.type=2 #0: no fill 1: as a poligon 2:to baseline dataset.fill.color=7 dataset.line.color = 7 else: dataset.line.color = colors[i] dataset.line.linewidth = 3 if cont==3 or cont==5: dataset.line.linestyle = 4 cont+=1 graph.legend.char_size = 1. graph.legend.loc = (.2,.81) graph.legend.box_linestyle=0 # 0 meanis NO legend box graph.legend.box_fill_color=7 # 0 means NO legend box # obj1.drawtext.text="YAY!" # 0 means NO legend box grace.autoscale() grace.write_file(filename)
self.world.xmin = 0 self.world.xmax = 10 self.xaxis.label.text = \ LatexString(r'\6X\4 = $\langle$ \xb\4\sj\N $\rangle$') class Graph2(PDFGraph): def __init__(self, *args, **kwargs): PDFGraph.__init__(self, *args, **kwargs) self.set_view(0.75, 0.15, 1.2, 0.6) self.world.xmin = 0 self.world.xmax = 10 self.xaxis.label.text = \ LatexString(r'\6X\4 = $\langle$ \xb\4\sj\N $\rangle$') # make the plot grace = Grace() grace.add_drawing_object(DrawText, text='Currently available LaTeX characters', x=0.08, y=0.92, char_size=0.8, font=6, just=4) grace.add_drawing_object(DrawLine, start=(0.08, 0.915), end=(1.22, 0.915), linewidth=1.0) mod = (len(CONVERT) / 5) + 1 for index, (latexString, graceString) in enumerate(sorted(CONVERT.items())): x = 0.1 + 0.20 * (index / mod) y = 0.895 - 0.0225 * (index % mod) # latexString = latexString.replace('\\', r'\\') # grace.add_drawing_object(DrawText, text=graceString, x=x, y=y, # char_size=0.6, font=4, just=1) # grace.add_drawing_object(DrawText, text=latexString, x=x+0.01, y=y, # char_size=0.6, font=4, just=0)
def cdf_plotting(self): Dir = self.Dir data = self.plotdata grace = Grace(colors=ColorBrewerScheme('Paired')) graph = grace.add_graph() graph.set_labels(str(self.axis_labels[self.key]['x_axis']), str(self.axis_labels[self.key]['y_axis'])) dataset1 = graph.add_dataset(data) dataset1.line.type = 0 dataset1.line.color = 1 dataset1.line.linewidth = 4.0 dataset1.symbol.fill_color = 'white' dataset1.symbol.shape = 1 dataset1.symbol.size = 0.9 dataset1.symbol.linewidth = 1.75 dataset1.symbol.color = 1 dataset1.symbol.color = 'Paired-5' graph.legend.box_color = 0 graph.legend.char_size = 0.85 graph.legend.loc = (0.55, 0.80) if self.axis_format[self.key] == "T": graph.xaxis.set_log() else: graph.autoscalex() graph.yaxis.set_log() if self.key == "activity": xmaxx = 10000 else: xmaxx = float( math.ceil( float(max(self.datalist)) + .1 * float(max(self.datalist)))) if (self.key == "percentage_weight_loss" or self.key =="weight_change" or\ self.key == "n_weight_loss" or self.key == "percentage_weight_change"): xminx = float( math.floor( float( min(self.datalist) + 0.1 * float((min(self.datalist)))))) else: xminx = 0.0 ymin_val = min(data, key=operator.itemgetter(1)) if ymin_val >= 0 and ymin_val <= 0.1: ymin = 0.1 elif ymin_val > 0.1 and ymin_val <= 0.01: ymin = 0.01 elif ymin_val > 0.01 and ymin_val <= 0.001: ymin = 0.001 elif ymin_val > 0.001 and ymin_val <= 0.0001: ymin = 0.0001 else: ymin = 0.00001 xmin, xmax, ymin, ymax = xminx, xmaxx, 0.001, 1 print "xmin,xmax, ymin, ymax", xmin, xmax, ymin, ymax graph.set_world(xmin, ymin, xmax, ymax) #graph.autoscalex() graph.xaxis.set_format('decimal', 0) graph.title.text = str(self.filename) graph.title.size = 1.1 graph.subtitle.size = 0.9 grace.write_file(Dir + str(self.filename) + '.agr')
def output_grace(data, seedname='out', up=True, down=True): """ Creates a .agr Grace file of the band structure Parameters ---------- data: Data object Data object containing the frequencies and other data required for plotting (qpts, n_ions, cell_vecs) seedname : string, optional Determines the figure title and output file name, seedname.agr. Default: 'out' up : boolean, optional Whether to plot spin up frequencies (if applicable). Default: True down : boolean, optional Whether to plot spin down frequencies (if applicable). Default: True """ try: from PyGrace.grace import Grace except ImportError: warnings.warn(('PyGrace is not installed, attempting to write .agr ' 'Grace file anyway. If using Python 2, you can install' ' PyGrace from https://github.com/pygrace/pygrace'), stacklevel=2) # Do calculations required for axis, tick labels etc. # Calculate distance along x axis cell_vec = (data.cell_vec.to('angstrom').magnitude) recip_latt = reciprocal_lattice(cell_vec) abscissa = calc_abscissa(data.qpts, recip_latt) # Calculate x-axis (recip space) ticks and labels xlabels, qpts_with_labels = recip_space_labels(data) units_str = data._e_units inverse_unit_index = units_str.find('/') if inverse_unit_index > -1: units_str = units_str[inverse_unit_index + 1:] yaxis_label = '\\f{{Symbol}}e\\f{{}} ({0}\S-1\\N)'.format(units_str) else: yaxis_label = '\\f{{Symbol}}e\\f{{}} ({0})'.format(units_str) # Format tick labels for i, label in enumerate(xlabels): if label == 'GAMMA': # Format gamma symbol label = '\\f{Symbol}G\\f{}' if 'PyGrace' in sys.modules: grace = Grace() grace.background_fill = 'on' graph = grace.add_graph() graph.yaxis.label.text = yaxis_label graph.xaxis.tick.set_spec_ticks(abscissa[qpts_with_labels].tolist(), [], xlabels.tolist()) graph.xaxis.tick.major_grid = 'on' if len(max(xlabels, key=len)) >= 11: graph.xaxis.ticklabel.configure(angle=315, char_size=1.0) for i in range(data.n_branches): if up: ds = graph.add_dataset( zip(abscissa, data.freqs[:, i].magnitude)) ds.line.configure(linewidth=2.0, color=i % 16) ds.symbol.shape = 0 if down and hasattr(data, 'freq_down') and len(data.freq_down) > 0: ds = graph.add_dataset( zip(abscissa, data.freq_down[:, i].magnitude)) ds.line.configure(linewidth=2.0, color=i % 16) ds.symbol.shape = 0 if hasattr(data, 'fermi'): for i, ef in enumerate(data.fermi.magnitude): ds = graph.add_dataset(zip([0, abscissa[-1]], [ef, ef])) ds.line.configure(linewidth=2.0, color=1, linestyle=3) graph.set_world_to_limits() grace.write_file(seedname + '.agr') else: with open(seedname + '.agr', 'w') as f: f.write('@with g0\n') f.write('@title "{0}"\n'.format(seedname)) f.write('@view 0.150000, 0.250000, 0.700000, 0.850000\n') f.write('@world xmin 0\n') f.write('@world xmax {0:.3f}\n'.format(abscissa[-1] + 0.002)) f.write('@world ymin 0\n') f.write('@default linewidth 2.0\n') f.write('@default char size 1.5\n') f.write('@autoscale onread yaxes\n') f.write('@yaxis bar linewidth 2.0\n') f.write('@yaxis label "{0}"\n'.format(yaxis_label)) f.write('@yaxis label char size 1.5\n') f.write('@yaxis ticklabel char size 1.5\n') f.write('@xaxis bar linewidth 2.0\n') f.write('@xaxis label char size 1.5\n') f.write('@xaxis tick major linewidth 1.6\n') f.write('@xaxis tick major grid on\n') f.write('@xaxis tick spec type both\n') f.write('@xaxis tick spec {0:d}\n'.format(len(xlabels))) # Rotate long tick labels if len(max(xlabels, key=len)) <= 11: f.write('@xaxis ticklabel char size 1.5\n') else: f.write('@xaxis ticklabel char size 1.0\n') f.write('@xaxis ticklabel angle 315\n') for i, label in enumerate(xlabels): f.write('@xaxis tick major {0:d},{1:8.3f}\n'.format( i, abscissa[qpts_with_labels[i]])) f.write('@xaxis ticklabel {0:d},"{1}"\n'.format(i, label)) # Write frequencies for i in range(data.n_branches): n_sets = 0 if up: f.write('@target G0.S{0:d}\n'.format(n_sets)) f.write('@type xy\n') for j, freq in enumerate(data.freqs[:, i].magnitude): f.write('{0: .15e} {1: .15e}\n'.format( abscissa[j], freq)) n_sets += 1 if (down and hasattr(data, 'freq_down') and len(data.freq_down) > 0): f.write('@target G0.S{0:d}\n'.format(n_sets)) f.write('@type xy\n') for j, freq in enumerate(data.freq_down[:, i].magnitude): f.write('{0: .15e} {1: .15e}\n'.format( abscissa[j], freq)) n_sets += 1 f.write('&\n') # Write Fermi level if hasattr(data, 'fermi'): for i, ef in enumerate(data.fermi.magnitude): f.write('@ G0.S{0:d} line linestyle 3\n'.format( data.n_branches + i)) f.write( '@ G0.S{0:d} line color 1\n'.format(data.n_branches + i)) f.write('@target G0.S{0:d}\n'.format(data.n_branches + i)) f.write('@type xy\n') f.write('{0: .15e} {1: .15e}\n'.format(0, ef)) f.write('{0: .15e} {1: .15e}\n'.format(abscissa[-1], ef)) f.write('&\n')
def realmultilinegraph(list_of_list_data, xTitle, yTitle, list_yLegends, filename, colors): #ys is a list of y-series #1:black #2:red #3: light green #4:dark blue #5:yellow #6:light brown #7:grey #8:purple #9:cyan #10:pink #11:orange #12: purple2 #13:maroon #14:cyan2 #15:dark green grace = Grace() graph = grace.add_graph() # obj1 = grace.add_drawing_object(DrawText) # graph.title.text = graphTitle graph.title.size = 1.2 #graph.subtitle.text = subtitle graph.subtitle.size = .6 graph.xaxis.label.text = xTitle graph.xaxis.label.char_size = 2 graph.xaxis.ticklabel.format = 'Decimal' graph.xaxis.ticklabel.char_size = 2 graph.xaxis.ticklabel.prec = 2 graph.yaxis.label.text = yTitle graph.yaxis.label.char_size = 2 graph.yaxis.ticklabel.char_size = 2 graph.yaxis.ticklabel.format = 'Decimal' graph.yaxis.ticklabel.prec = 2 cont = 0 for i in range(len(list_of_list_data)): dataset = graph.add_dataset(list_of_list_data[i], type='xydy', legend=list_yLegends[i]) dataset.symbol.shape = 1 dataset.symbol.color = colors[i] dataset.symbol.fill_color = colors[i] dataset.line.linewidth = 3 dataset.errorbar.color = colors[i] dataset.line.color = colors[i] # dataset.line.color = colors[i] graph.legend.char_size = 1. graph.legend.loc = (.8, .41) graph.legend.box_linestyle = 0 # NO legend box grace.autoscale() grace.write_file(filename)
from PyGrace.drawing_objects import DrawText from PyGrace.Styles.el import ElSquareGraph, ElCircleDataSet import example_tools data = example_tools.logautoscale() # Demonstrate how the autoscaling works for logarithmic axes. In # particular demonstrate how to get ride of drawing objects that are # outside of bounds of graph #------------------------------------------------------------------------------ # make a nice figure #------------------------------------------------------------------------------ # instantiate a sweet figgy fig colors = ColorBrewerScheme("Set1") grace = Grace(colors=colors) # to add some data to graph, just add the DrawBox to the 'world' # coordinates. this ensures that all of the autoscaling will work # properly. graph = grace.add_graph(ElSquareGraph) dataset = graph.add_dataset(data,ElCircleDataSet,3) # add some drawing objects to graph graph.add_drawing_object(DrawText,loctype="world", x=0.001,y=0.001,text="Now you see me", color=2) graph.add_drawing_object(DrawText,loctype="world", x=0,y=0,text="Now you don't", color=2)
self.symbol.configure(shape=1, fill_color=color, color=color) self.line.configure(type=0, linestyle=0, color=color) class ManyScatterGraph(Graph): def __init__(self, dataList, *args, **kwargs): Graph.__init__(self, *args, **kwargs) # make graph square self.view.xmax = self.view.xmin + (self.view.ymax - self.view.ymin) # add the datasets that are given for index, data in enumerate(dataList): self.dataset = self.add_dataset(data, ScatterPoints, index + 2) # autoscale the axes self.autoscale() # ---------------------------------- this is the part where YOU do the analysis # dataList is a list of lists, each one of (x, y) points import example_tools dataList = example_tools.simplesubclass() # make the plot grace = Grace(colors=ColorBrewerScheme('Set1')) graph = grace.add_graph(ManyScatterGraph, dataList) graph.set_labels('Snerdwump', 'Sneezle') graph.format_for_print(6) # print the grace (.agr format) to a file grace.write_file('03_simplesubclass.agr')
# Define a couple of link sets links1 = [ ('B', 'a1'), ('a2', 'a4'), ('a4', 'a2'), ] links2 = [ ('B', 'a2'), ('B', 'a3'), ('a4', 'B'), ('a5', 'a4'), ('a4', 'a5'), ] # Create the grace instance grace = Grace() # Create the network graph instance network = grace.add_graph(Network) # Make sure the view and the world are squares # This is *essential* since the link drawing code relies # upon the world and view being defined BEFORE their instantiation. # (You want to work with squares in any case, because # otherwise coordinates shift, distances are misperceived) network.set_view(0,0,1,1) network.set_world(0,0,1,1) # ---------------------------- # Add the node sets
from PyGrace.grace import Grace from PyGrace.colors import ColorBrewerScheme from PyGrace.dataset import SYMBOLS, LINESTYLES # ---------------------------------- this is the part where YOU do the analysis # data0, data1, and data2 are all lists of (x, y) points. import example_tools data0, data1, data2 = example_tools.dataset_features() grace = Grace(colors=ColorBrewerScheme('Set1')) graph = grace.add_graph() graph.xaxis.label.text = 'x' graph.yaxis.label.text = 'y' # add data sets dataset0 = graph.add_dataset(data0) dataset1 = graph.add_dataset(data1) dataset2 = graph.add_dataset(data2) # autoscale the axes graph.autoscale() # set symbol sizes for dataset in graph.datasets: dataset.symbol.size = 0.75 dataset.symbol.linewidth = 2.0 # these methods emulate some functions in xmgrace that automatically # set the symbols, colors, and linestyles to be different for each # dataset in a graph.
char_size=char_size, x=x, y=y, color=color, font=font, loctype=loctype) newRow.append(obj) x += xSpace self.table.append(newRow) y += ySpace if __name__ == '__main__': from random import normalvariate as nv from PyGrace.grace import Grace grace = Grace() graph = grace.add_graph() table = [ [r'\xm\4:', r'1.0'], [r'\xs\4:', r'2.0'], [r'\xg\4:', r'3.0'], ] # table = [(r'x', r'y')] # data = [('%.2f' % nv(0,1), '%.2f' % nv(0, 1)) for i in range(6)] # table.extend(data) graph.add_drawing_object(DrawTable, table, xSpace=0.15)
# find bounds of pdf x0s,y0s,x1s,y1s,pdfs = zip(*data) maxpdf=max(pdfs) minpdf = float("inf") for pdf in pdfs: if pdf<minpdf and pdf>0.0: minpdf=pdf # instantiate a sweet figgy fig colors = ColorBrewerScheme("YlOrBr",n=253) # this is the maximum number of colors # you can change the opacity percent of a colorscheme if you want: # colors.change_opacity(20, exclude_black=False) grace = Grace(colors=colors) # add a colorbar colorbar = grace.add_graph(ElLogColorBar,domain=(minpdf,maxpdf), scale=LOGARITHMIC_SCALE,autoscale=False) # to add some data to graph, just add SolidRectangle datasets graph = grace.add_graph() graph.copy_format(ElGraph) for (x0,y0,x1,y1,pdf) in data: if pdf > 0.0: color = colorbar.z2color(pdf) # you can change the opacity percentage of a single color, as well # color.change_opacity(60) graph.add_dataset([(x0,y0), (x1,y1)], SolidRectangle, color)
'C': (0.6, 0.2), } # Define a couple of link sets links1 = [ ('B', 'a1'), ('a2', 'a4'), ] links2 = [ ('B', 'a2'), ('B', 'a3'), ('B', 'a4'), ] # Create the grace instance grace = Grace() # Create the network graph instance network = grace.add_graph(Network) # Add the node sets network.add_node_set(nodeset1_xysize, type='xysize', color=3) network.add_node_set(nodeset2_xy, size=6, color=13, line_width=6, line_color=12) # Add the link sets linkSet = network.add_link_set(links1, size=0.5, color=2) linkSet.line.linestyle = 3 # dashed links
from PyGrace.grace import Grace from PyGrace.colors import ColorBrewerScheme # ---------------------------------- this is the part where YOU do the analysis # data1 and data2 are both lists of (x, y) points. import example_tools data1, data2 = example_tools.singleplot() grace = Grace(colors=ColorBrewerScheme('Paired')) graph = grace.add_graph() graph.xaxis.label.text = 'Fake X' graph.yaxis.label.text = 'Fake Y' dataset1 = graph.add_dataset(data1, legend='Set 1') dataset1.symbol.fill_color = 'Paired-0' dataset2 = graph.add_dataset(data2, legend='Set 2') dataset2.symbol.fill_color = 'Paired-1' graph.set_world_to_limits() graph.logxy() grace.write_file('01_singleplot.agr')
} # Define a couple of link sets links1 = [ ('B', 'a1'), ('a2', 'a4'), ] links2 = [ ('B', 'a2'), ('B', 'a3'), ('B', 'a4'), ] # Create the grace instance grace = Grace() # Create the network graph instance network = grace.add_graph(Network) # Add the node sets network.add_node_set(nodeset1_xysize, type='xysize', color=3) network.add_node_set(nodeset2_xy, size=6, color=13, line_width=6, line_color=12) # Add the link sets linkSet = network.add_link_set(links1, size=0.5, color=2) linkSet.line.linestyle = 3 # dashed links network.add_link_set(links2, size=5, color=9) # Add a single node and a single link network.add_node('alone', (.3, .4, 5), type='xycolor')
from PyGrace.grace import Grace from PyGrace.colors import ColorBrewerScheme from PyGrace.drawing_objects import DrawText # ---------------------------------- this is the part where YOU do the analysis # all datasets are lists of (x, y) points import example_tools data1, data2, data3, data4, data5 = example_tools.multiplot() # make a Grace instance with the "Set1" color scheme grace = Grace(colors=ColorBrewerScheme('Set1')) # this function returns the maximum x and y "view" values to fit in the page xView, yView = grace.set_landscape() # create graphs and set locations on page graph1 = grace.add_graph() graph1.set_view(0.10 * xView, 0.55 * yView, 0.90 * xView, 0.90 * yView) # to illustrate the use of drawing objects, and just to make things a little # more complicated, here is a manually added label to graph 1. title1 = graph1.add_drawing_object(DrawText, text='(a) Regression', x=0.10 * xView, y=0.91 * yView, just=4) # this will set the axis labels. it is a good idea to use raw strings (r'') # so that backslashes (which are used to give xmgrace text formatting commands) # are not used as escape characters. graph1.set_labels(r'\xt\4', r'\xg\4(\xt\4)')
import sys sys.path.append("../../") sys.path.append("../") from PyGrace.grace import Grace # make an instance of the Grace class grace = Grace() # add a Graph as a "child" of the grace instance graph = grace.add_graph() graph.title.text = "Hello, world!" # add a simple DataSet as a "child" of the graph instance. A list of data is # always the required first argument to add_dataset. data = [(0, 0), (0.5, 0.75), (1, 1)] dataset = graph.add_dataset(data) # print the grace to a file (.agr format) grace.write_file("00_helloworld.agr")
from PyGrace.drawing_objects import DrawText from PyGrace.Styles.el import ElSquareGraph, ElCircleDataSet import example_tools data = example_tools.logautoscale() # Demonstrate how the autoscaling works for logarithmic axes. In # particular demonstrate how to get ride of drawing objects that are # outside of bounds of graph #------------------------------------------------------------------------------ # make a nice figure #------------------------------------------------------------------------------ # instantiate a sweet figgy fig colors = ColorBrewerScheme("Set1") grace = Grace(colors=colors) # to add some data to graph, just add the DrawBox to the 'world' # coordinates. this ensures that all of the autoscaling will work # properly. graph = grace.add_graph(ElSquareGraph) dataset = graph.add_dataset(data, ElCircleDataSet, 3) # add some drawing objects to graph graph.add_drawing_object(DrawText, loctype="world", x=0.001, y=0.001, text="Now you see me", color=2) graph.add_drawing_object(DrawText,
from PyGrace.grace import Grace # make an instance of the Grace class grace = Grace() # add a Graph as a "child" of the grace instance graph = grace.add_graph() graph.title.text = 'Hello, world!' # add a simple DataSet as a "child" of the graph instance. A list of data is # always the required first argument to add_dataset. data = [(0, 0), (0.5, 0.75), (1, 1)] dataset = graph.add_dataset(data) # print the grace to a file (.agr format) grace.write_file('00_helloworld.agr')
from PyGrace.grace import Grace from PyGrace.drawing_objects import DrawBox, DrawText, DrawLine, DrawEllipse grace = Grace() graph = grace.add_graph() graph.add_dataset([(0, 0), (1, 1)]) graph.add_drawing_object(DrawBox) graph.add_drawing_object(DrawText) graph.add_drawing_object(DrawLine) graph.add_drawing_object(DrawEllipse) grace.write_cheatsheet('cheatsheet.tex')
from PyGrace.grace import Grace from PyGrace.colors import ColorBrewerScheme from PyGrace.dataset import SYMBOLS, LINESTYLES from PyGrace.Extensions.tree import Tree # ---------------------------------- this is the part where YOU do the analysis # data is a string of a newick tree import example_tools data = example_tools.tree() # make an instance of the Grace class grace = Grace(colors=ColorBrewerScheme('Set1')) # add a Tree Graph as a "child" of the grace instance graph = grace.add_graph(Tree, orientation='down') # load the data tree = graph.add_tree(data, ) # change the x-axis ticklabel's angle # by default (since names tend to be long) the labels are rotated # but in this example we just use letters so there is no need to rotate graph.xaxis.ticklabel.configure(angle=0, ) # autoscale the axes graph.autoscale() #graph.autoformat() # print out the grace grace.write_file('14_phylogenetic_tree.agr')
from PyGrace.grace import Grace from PyGrace.colors import ColorBrewerScheme from PyGrace.dataset import SYMBOLS, LINESTYLES from PyGrace.Extensions.tree import Tree # ---------------------------------- this is the part where YOU do the analysis # data is a string of a newick tree import example_tools data = example_tools.tree() # make an instance of the Grace class grace = Grace(colors=ColorBrewerScheme('Set1')) # add a Tree Graph as a "child" of the grace instance graph = grace.add_graph(Tree,orientation='down') # load the data tree = graph.add_tree(data,) # change the x-axis ticklabel's angle # by default (since names tend to be long) the labels are rotated # but in this example we just use letters so there is no need to rotate graph.xaxis.ticklabel.configure(angle=0,) # autoscale the axes graph.autoscale() #graph.autoformat() # print out the grace grace.write_file('14_phylogenetic_tree.agr')