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 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 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 _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')
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)')
# make a nice figure #------------------------------------------------------------------------------ # get the data import example_tools data = example_tools.colorplot() # 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:
from PyGrace.axis import LINEAR_SCALE, LOGARITHMIC_SCALE 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)
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')
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')