def plotter_Ani(out_file_list, dim_s, angle2): dim_ge = dim_s[1] angle = out_file_list[-1] del out_file_list[-1] data_max = out_file_list[-1] del out_file_list[-1] data_min = out_file_list[-1] del out_file_list[-1] print(data_min, data_max) name_col = out_file_list[1][:] col_num = name_col.index(angle) + 1 del out_file_list[1][:] g = Gnuplot.Gnuplot() ranges = 'set yrange[%s:%s]' % (str(data_min), str(data_max)) g(ranges) g.xlabel(angle2) g.ylabel('V [Hartree]') g('set terminal gif animate delay 50') g('set xtic scale 1 font ",10"') g('set grid') fileout = 'set out "myAni.gif"' g(fileout) for entry in out_file_list[ 0]: # out_file_list[0]: index necessary, because it's a list of list gnu_para = str(col_num) + ':1' databuff1 = Gnuplot.File(entry, using=gnu_para, title=angle) gnu_para = str(col_num) + ':2' databuff2 = Gnuplot.File(entry, using=gnu_para, title=angle) gnu_para = str(col_num) + ':3' databuff3 = Gnuplot.File(entry, using=gnu_para, title=angle) g.plot(databuff1, databuff2, databuff3) g('unset output')
def grafico(self, other, \ interp='n', \ cifre=('"%.0s*10^{%S}"','"%.0s*10^{%S}"'), \ terminal='x11', \ etichetteassi=('x', 'y'), \ output='grafico'): glt = Gnuplot.Gnuplot(debug=1) #apre gnuplot glt('set tics nomirror; unset key; set format x %s; set format y %s' % cifre) glt('set terminal %s' % terminal) glt('set output "%s"' % output) glt.xlabel(etichetteassi[0]) glt.ylabel(etichetteassi[1]) nome = 'temp' colonne = (1, 2) scrivivalori((self.valori, other.valori), nome) if interp != 'n': parametri = self.interpolazionelineare(other) f = Gnuplot.Func('%.14f*x%+.14f' % (parametri[2], parametri[0])) glt.plot(Gnuplot.File(nome, using=colonne), f) if terminal == 'x11': chiudigrafico() return glt.plot(Gnuplot.File(nome, using=colonne)) glt('set output') if terminal == 'x11': chiudigrafico()
def plotter_Ani(out_file_list, dim_s, angle_fest): dim_ge = dim_s[1] angle = out_file_list[-1] del out_file_list[-1] data_max = out_file_list[-1] del out_file_list[-1] data_min = out_file_list[-1] del out_file_list[-1] name_col = out_file_list[1][:] col_num = name_col.index(angle) + 1 del out_file_list[1][:] g = Gnuplot.Gnuplot() ranges = 'set yrange[%s:%s]' % (str(data_min), str(data_max)) g(ranges) g('set terminal gif enhanced animate delay 50') g.xlabel(angle[:5].lower() + ' [Degree]') # [:5] nur ersten 5 Characters des Strings g.ylabel('V [cm^-1]') g('set xtic scale 1 font ",10"') g('set grid') fileout = 'set out "' + angle_fest + '_fest/myAni.gif"' g(fileout) for entry in out_file_list[ 0]: # out_file_list[0]: index necessary, because it's a list of list gnu_para = str(col_num) + ':1' databuff1 = Gnuplot.File(entry, using=gnu_para, title='A_1 (MRCI)') gnu_para = str(col_num) + ':2' databuff2 = Gnuplot.File(entry, using=gnu_para, title='E (MRCI)') gnu_para = str(col_num) + ':3' databuff3 = Gnuplot.File(entry, using=gnu_para, title='E (MRCI)') g.plot(databuff1, databuff2, databuff3) g('unset output')
def display(): """Demonstrate the Gnuplot package.""" yAxisBound = commands.getstatusoutput('sudo ./readVoltsScale') #Create a plot of current Oscilloscope Output g = Gnuplot.Gnuplot(debug=1) #Setup title, axis labels etc. g.title('MicrOscope') g('set style data linespoints') g('set grid') databuff = Gnuplot.File("values.data", using='1:2') g.plot(databuff) #Setting the volts/div if (yAxisBound[1] == '13'): g('set yrange ["0":"5"]') elif (yAxisBound[1] == '19'): g('set yrange ["0":"2.5"]') elif (yAxisBound[1] == '26'): g('set yrange ["2.5":"5"]') else: g('set yrange ["0":"5"]') g.hardcopy(filename="micrOscopeOutput.png", terminal="png")
def plotXYZPoint(path, fields='3:4:5', state=None, g=None): if g == None: g = Gnuplot.Gnuplot() if not options.terminal: g('set terminal png') g('set output \'%s/%s_%s.png\'' % (options.graphicsdirectory, options.graphicsprefixname, 'plotXYZPoint')) if state != None: state.append(g) g.title('Points observation in 3-D') g.xlabel('x-axes') g.ylabel('y-axes') g.zlabel('z-axes') files=[] for filename in getSortedFiles(path): files.append(Gnuplot.File(path + '/' + filename, using=fields, with_='points', #title='distribution \'' + filename + '\'' title="" ) ) if len(files) > 0: g.splot(*files) return g
def plotXPointYFitness(path, fields='3:1', state=None, g=None): if g == None: g = Gnuplot.Gnuplot() if not options.terminal: g('set terminal png') g('set output \'%s/%s_%s.png\'' % (options.graphicsdirectory, options.graphicsprefixname, 'plotXPointYFitness')) if state != None: state.append(g) g.title('Fitness observation') g.xlabel('Coordinates') g.ylabel('Fitness (Quality)') files=[] for filename in getSortedFiles(path): files.append(Gnuplot.File(path + '/' + filename, using=fields, with_='points', #title='distribution \'' + filename + '\'' title="" ) ) if len(files) > 0: g.plot(*files) return g
def PlotValues(values1, values2): fileName1 = tempfile.mktemp() with open(fileName1, 'w') as f: for value in values1: f.write('%s\n' % value) fileName2 = tempfile.mktemp() with open(fileName2, 'w') as f: for value in values2: f.write('%s\n' % value) g = Gnuplot.Gnuplot(debug=1) g.clear() g.plot(Gnuplot.File(fileName1, with_='lines'), Gnuplot.File(fileName2, with_='lines')) wait('Press Enter')
def create_graph(graph_title, temp_data_file, graph_file): '''Create a PNG graph out of passed data using Gnuplot Python wrapper around bare gnuplot utility ''' if not os.path.exists(temp_data_file.fname): print '\nWARNING no data in %s file yet\n' % temp_data_file.fname return False seven_days_data = temp_data_file.extract_last_n_days(7) min_temp, max_temp = TempDataFile( seven_days_data).get_min_max_temperature() floor = int(float(min_temp) / 10) * 10 ceil = (1 + int(max_temp / 10)) * 10 if min_temp < 0: floor -= 10 g = Gnuplot.Gnuplot(debug=0) # set debug=1 for a verbose run g.title(graph_title) g('set xdata time') g('set style data lines') g('set term png size 1200, 900') g('set timefmt "%Y%m%d%H%M%S"') # date format int the FILE g('set ylabel "temperature" ') g('set yrange [ "%d" : "%d" ]' % (floor, ceil)) # dynamically adjust min/max temperature scale g('set grid') g('set bmargin 6') g('set xtics rotate by 90 offset 0, -5.4') # 4.8 => 5.4 (label offset) g('set xtics format "%d-%b %H:%M" time') # date/time format on the GRAPH g('set linetype 1 linecolor rgb "#C00000"') g('set linetype 2 linecolor rgb "0x0000C0"') g('set output "%s"' % graph_file) f = Gnuplot.File(seven_days_data, using='1:2 t "air temp.", "" u 1:3 t "apparent temp."') g.plot(f) return True
def barrierPlotter(): # Reads the names of the files containing barrier benchmark data. # (File names need to be written in increasing thread count order) # Concatenates these files into a file called BarrierPlotter_catFiles.dat # Plots the time per reps against the number of threads to an eps file. global gplotter while (True): #read file name print "Enter the name of the file containing barrier data, 0 to exit..." fileName = sys.stdin.readline() #Remove \n from fileName fileName = fileName.rstrip('\n') if (fileName != '0'): #cat the file to BarrierPlotter_catFiles.dat os.system("cat " + fileName + ">> BarrierPlotter_catFiles.dat") else: #exit out of loop break #Find output file name for the plot print("Enter file name for hardcopy of barrier plot...") outFileName = sys.stdin.readline() outFormat = ".eps" outFormat = outFormat.rstrip('\n') outFileName = outFileName.rstrip('\n') + outFormat #Plot barrier data... #1) Clear gplotter.clear() #2) Set axis labels gplotter('set border') gplotter.xlabel('Number of Threads') gplotter.ylabel('Time (seconds)') gplotter('set autoscale x') gplotter('set autoscale y') #gplotter('set format y "10^{%L}"') #3) Don't want a legend for barrier plot gplotter('set key off') #gap between legend entries #4) Plot BarrierPlotter_catFiles.dat using column 2 (number of threads) and column 3 (time per rep) gplotter.plot( Gnuplot.File("BarrierPlotter_catFiles.dat", using=(2, 3), with_='linespoints')) #5) Write hardcopy print 'Hardcopy written to:', outFileName gplotter.hardcopy(outFileName, eps=1, color=1, enhanced=1) #6) Uncomment if want to convert the eps output file to a pdf #gplotter.close() #convertCommand = "epstopdf " + outFileName #os.system(convertCommand) #Remove BarrierPlotter_catFiles.dat os.system("rm BarrierPlotter_catFiles.dat")
def qmultiPlotAddPlot( dataset, g, t, withLineWidth ) : f = fudgeFileMisc.fudgeTempFile( ) for x, y in dataset.copyDataToXYs( ) : f.write( "%.12e %.12e\n" % ( x, y ) ) f.close( ) gf = Gnuplot.File( f.getName( ), title = t ) # , with = withLineWidth ) gf._options['with'] = ( withLineWidth, 'with ' + withLineWidth ) g._add_to_queue( [ gf ] )
def PlotPercentiles(self): fileName = tempfile.mktemp() with open(fileName, 'w') as f: for value in self.sortedValues: f.write('%s\n' % value) g = Gnuplot.Gnuplot(debug=1) g.clear() g.plot(Gnuplot.File(fileName, with_='lines')) wait('Press Enter')
def DoPlot(ewald, p3me): f = open("p.tmp", "w") for i in range(len(p3me)): f.write("%f %f\n" % (p3me[i][0], p3me[i][1])) f.close() f = open("e.tmp", "w") for i in range(len(ewald)): f.write("%f %f\n" % (1.0/ewald[i][0], ewald[i][1])) f.close() g = Gnuplot.Gnuplot(debug=0) g('set terminal png') g('set output "P3ME_Ewald.png"') g.set_boolean('x2tics', 1) g.ylabel('TotalEnergy') g.set_string('x2label', 'P3ME Grid Spacing') g.set_string('xlabel', '1/EwaldKMax') g.set_range('xtics', 'nomirror') g.plot(Gnuplot.File("p.tmp", using='1:2', with='linespoints', axes='x2y1', title='p3me'), Gnuplot.File("e.tmp", using='1:2', with='linespoints', axes='x1y1', title='ewald'))
def plot_link_length(lengths, width=default_width, height=default_height, filename=None): if len(lengths) is 0: logging.warning("No link lengths to plot.") lengths = [[0.01]] g = g_init(width, height, filename) g.title('Link Length Distribution') g.xlabel('Link Length (delta location)') g.ylabel('Percent links with this length or less') add_sample_size_label(g, len(lengths)) g('set logscale x') # As location is circular and [0,1), largest difference is 0.5. g.set(xrange='[0.00001:0.5]') g.set(yrange='[0:100]') g.plot(Gnuplot.Data(CDF(lengths), smooth='cumulative', title='Measured'), Gnuplot.File('ideal-link', smooth='cumulative', title='Ideal'), Gnuplot.File('flat-link', smooth='cumulative', title='Flat'))
def grafico(nomefile, colonne=(1, 2), etichetteassi=('x', 'y'), cifredecimali=('.g', '.g')): decimali = ('"%' + cifredecimali[0] + '"', '"%' + cifredecimali[1] + '"') (x, y) = legginumeri(nomefile, colonne) parametri = interpolazionelineare(x, y) f = Gnuplot.Func('%.14f*x%+.14f' % (parametri[2], parametri[0])) glt = Gnuplot.Gnuplot(debug=1) #apre gnuplot glt('set tics nomirror;unset key;set format x %s;set format y %s' % decimali) glt.xlabel(etichetteassi[0]) glt.ylabel(etichetteassi[1]) glt.plot(Gnuplot.File(nomefile, using=colonne), f)
def Plot(self): g = Gnuplot.Gnuplot() g.clear() plots = [] color = 1 g.xlabel('time (seconds)') for plot in self.plots: fn = plot.WriteToTempFile() g.ylabel(plot.title) plots.append(Gnuplot.File(fn, with_='lines linecolor %d' % color, title='%s (%.2f - %.2f)' % (plot.title, plot.min, plot.max))) if plot.IsMidLineVisible(): plots.append(Gnuplot.Func('%.4f' % plot.GetMidLine(), with_='lines linecolor %d' % color, title='')) color += 1 g.plot(*plots) wait()
def generatePlot3D(filename): plot = Gnuplot.Gnuplot() plot("set terminal pngcairo size 640,480 enhanced font 'Verdana,10") plot("set output '{}'".format(filename)) plot("set border 4095 front linetype 0 linewidth 1.000") plot("set view 60,30") plot("set xlabel 'r'") plot("set ylabel 'm'") plot("set zlabel 'max_score'") plot("set title 'Different x-y measurement'") plot("set ztics offset 1") plot("set zrange [0:80000]") plot("set palette defined (0.001 'green', 0.01 'yellow', 0.9 'red')") plot("set pm3d") plot.splot(Gnuplot.File('test_results_R_max_score.txt', using=(1,2,3) ))#, with_="lines linecolor palette")) return
def display(): """Demonstrate the Gnuplot package.""" #Create a plot of current Oscilloscope Output g = Gnuplot.Gnuplot(debug=1) #Setup title, axis labels etc. #g = setupScopeScreen(g) g.title('MicrOscope') g('set data style linespoints') databuff = Gnuplot.File("values.data", using='1:2') g.plot(databuff) # gnuplot commands to cause plot to scroll, continually adding data # try compiling, the syntax might be a tad off g('pause 1') g('reread') raw_input('Please press return to continue....\n')
def graficoPST(nomefile, colonne=(1, 2), etichetteassi=('x', 'y'), cifredecimali=('.g', '.g')): glt = Gnuplot.Gnuplot(debug=1) #apre gnuplot glt('set terminal pstricks; set output %s' % ('"' + nomefile + '.tex"')) decimali = ('"%' + cifredecimali[0] + '"', '"%' + cifredecimali[1] + '"') (x, y) = legginumeri(nomefile, colonne) parametri = interpolazionelineare(x, y) f = Gnuplot.Func('%.14f*x%+.14f' % (parametri[2], parametri[0])) #glt = Gnuplot.Gnuplot(debug=1) #apre gnuplot glt('set tics nomirror;unset key;set format x %s;set format y %s' % decimali) glt('set xlabel %s; set ylabel %s' % etichetteassi) glt.plot(Gnuplot.File(nomefile, every=10, using=colonne), f) glt('set output')
def __init__(self, filename, title=None, datatitle=None, debug=0): self.gp = Gnuplot.Gnuplot(debug=debug) fp = open(filename, "r") line = fp.readline() while line: line = line.strip() if line.find('"') >= 0: data = line.split(" ") label = line[line.find('"') + 2:-1] self.gp('set label "%s" at %f,%f' % (label, float(data[0]), float(data[1]))) line = fp.readline() fp.close() self.file = Gnuplot.File(filename) self.gp('set data style lines') self.gp.title(title) self.file.set_option(title=datatitle)
def plotParams(path, field='1', state=None, g=None): if g == None: g = Gnuplot.Gnuplot() if not options.terminal: g('set terminal png') g('set output \'%s/%s_%s.png\'' % (options.graphicsdirectory, options.graphicsprefixname, 'plotXYZPoint')) if state != None: state.append(g) g.title('Hyper-volume comparaison through all dimensions') g.xlabel('Iterations') g.ylabel('Hyper-volume') g.plot(Gnuplot.File(path, with_='lines', using=field, title='multivariate distribution narrowing')) return g
def make_graph_png(): make_graph_data() g = Gnuplot.Gnuplot() g.reset() graph_title = ('Speed Camera Count by Hour where speed gt %s' % SPEED_OVER) g.title(graph_title) png_file_path = ('set output "%s"' % GRAPH_PATH) g(png_file_path) g.xlabel('Date') g.ylabel('Count') g("set autoscale") g("set key off") g("set grid") g("set terminal png size 900,600") g("set xtics rotate") g("set xdata time") g('set timefmt "%Y%m%d %H"') g('set format x "%Y-%m-%d"') databuff = Gnuplot.File(GRAPH_DATA_PATH, using='1:3', with_='boxes fill solid') g.plot(databuff) logging.info("Saved Graph File To %s", GRAPH_PATH)
def main(): s_nav_log_input_file_name = sys.argv[1] print (s_nav_log_input_file_name) output_s_nav_file = open('gpsr_s_nav_tlm.csv', 'w') search_string = "$POS," csvHeader = "GPS_SOW_TIME (sec), SBEE_X, SBEE_Y, SBEE_Z, VBEE_X, VBEE_Y, VBEE_Z, unknow0, unknow1, unknow2" with open(s_nav_log_input_file_name, 'rU') as s_nav_file_src: s_nav_input_log = s_nav_file_src.readlines() sim_data_list = [] for element in enumerate(s_nav_input_log): if (search_string in element[1]) == True: print (element[1]) line = element[1].replace(search_string, "") sim_data_list.append(line) output_s_nav_file.write("%s\n" % csvHeader) for item in sim_data_list: output_s_nav_file.write("%s" % item) s_nav_file_src.close() output_s_nav_file.close() print ("gpsr_s_nav_tlm.csv\n") print ("Next step ./time_log_alignment.py <DM log_nspo file>") g = Gnuplot.Gnuplot(persist = 1) g('set grid') g('set key left ') g('set title noenhanced') g('set label 1 at screen 0.92, screen 0.6 left') g.title('GPS-S-NAV-TLM') g.xlabel('Sequence (50ms)') g.ylabel('GPS Time (sec)') plotdata = Gnuplot.File('gpsr_s_nav_tlm.csv', using = '0:1', with_ = 'line') g.plot(plotdata) g.hardcopy (filename = 'gpsr_s_nav_tlm.png', terminal = 'png') # write last plot to another terminal
def __init__(self, fileName, dimension, title="", active=True, replot=None, xColumn=1, yColumn=2, zColumn=3, tColumn=None): if (title == ""): title = fileName fudgeNdMultiPlotItem.__init__(self, title, dimension, active=active, xColumn=xColumn, yColumn=yColumn, zColumn=zColumn, tColumn=yColumn) self.gnuPlotItem = fileName self.gnuPlotItem = Gnuplot.File(fileName, title=title)
import Gnuplot from numpy import * #Instantiate Gnuplot object (erzeugen) g = Gnuplot.Gnuplot() g.title("Title") g.xlabel('x') g.ylabel('y') g('set auto x') #g('set term pdf') g('set terminal gif animate delay 100') g('set xtic rotate by -45 scale 5 font ",2"') g('set grid') fileout = 'set out "myAni.gif"' g(fileout) for i in range(0, 40): phi = 0.5 + i * 9 # fileout='set out "output%s.pdf"' %phi filename1 = 'phi_%s.txt' % phi databuff = Gnuplot.File(filename1, using='6:3', with_='line', title=phi) g.plot(databuff) g('unset output')
if G2.parseParam(MocLog, 'Proc average ground speed', '$ProcAveGrndSpeed', 'cfg') != 0: ErrorExit('in parsing average ground speed from log') else: if G2.cfg[ '$AveGroundSpeed'] != 'null': # use radar config file value, if exists G2.cfg['$ProcAveGrndSpeed'] = G2.cfg['$AveGroundSpeed'] else: ErrorExit('AveGroundSpeed must be specified if MocompCalc is off') if G2.cfg[ '$EnablePlotMotionError'] == 'y': # make a pretty plot of the motion error g = Gnuplot.Gnuplot() g.xlabel('Track Time (secs)') g.ylabel('Motion Error (m)') data = Gnuplot.File(MocTxtFile, title='Motion error') g.plot(data) g.hardcopy(filename=MocPsFile, color=1, fontsize=20) time.sleep(5.0) del g, data print '(Motion error plot written to postscipt file)' #----------------------------- # Find DC offsets and I/Q ratio if G2.cfg['$EnableSniffDC'] == 'y': SDCRowsToProc = int(0.2 * int(G2.cfg['$InputPRIsToProc'])) SDCStartCol = int(0.25 * int(G2.cfg['$RngBinsToProc'])) SDCColsToProc = int(0.5 * int(G2.cfg['$RngBinsToProc'])) cmd = 'sniffdc '+G2.wrk['$RawDataFile']+\ ' '+G2.cfg['$RadarAzSamples']+' '+G2.cfg['$RadarRngBins']+\ ' StartRow='+G2.cfg['$StartG2PRI']+' RowsToProc='+`SDCRowsToProc`+\
wait('Style linespoints') f.set_option(with='linespoints') g.plot(f) wait('title=None') f.set_option(title=None) g.plot(f) wait('title="Sine of x"') f.set_option(title='Sine of x') g.plot(f) wait('axes=x2y2') f.set_option(axes='x2y2') g.plot(f) print '############### test File ###################################' wait('Generate a File from a filename') g.plot(Gnuplot.File(filename1)) wait('Style lines') g.plot(Gnuplot.File(filename1, with='lines')) wait('using=1, using=(1,)') g.plot(Gnuplot.File(filename1, using=1, with='lines'), Gnuplot.File(filename1, using=(1,), with='points')) wait('using=(1,2), using="1:3"') g.plot(Gnuplot.File(filename1, using=(1,2)), Gnuplot.File(filename1, using='1:3')) wait('every=5, every=(5,)') g.plot(Gnuplot.File(filename1, every=5, with='lines'), Gnuplot.File(filename1, every=(5,), with='points')) wait('every=(10,None,0), every="10::5"')
def main(): """Exercise the Gnuplot module.""" print( 'This program exercises many of the features of Gnuplot.py. The\n' 'commands that are actually sent to gnuplot are printed for your\n' 'enjoyment.') wait('Popping up a blank gnuplot window on your screen.') g = Gnuplot.Gnuplot(debug=1) g.clear() # Make two temporary files: if hasattr(tempfile, 'mkstemp'): ( fd, filename1, ) = tempfile.mkstemp(text=1) f = os.fdopen(fd, 'w') ( fd, filename2, ) = tempfile.mkstemp(text=1) else: filename1 = tempfile.mktemp() f = open(filename1, 'w') filename2 = tempfile.mktemp() try: for x in numpy.arange(100.) / 5. - 10.: f.write('%s %s %s\n' % (x, math.cos(x), math.sin(x))) f.close() print '############### test Func ###################################' wait('Plot a gnuplot-generated function') g.plot(Gnuplot.Func('sin(x)')) wait('Set title and axis labels and try replot()') g.title('Title') g.xlabel('x') g.ylabel('y') g.replot() wait('Style linespoints') g.plot(Gnuplot.Func('sin(x)', with_='linespoints')) wait('title=None') g.plot(Gnuplot.Func('sin(x)', title=None)) wait('title="Sine of x"') g.plot(Gnuplot.Func('sin(x)', title='Sine of x')) wait('axes=x2y2') g.plot(Gnuplot.Func('sin(x)', axes='x2y2', title='Sine of x')) print 'Change Func attributes after construction:' f = Gnuplot.Func('sin(x)') wait('Original') g.plot(f) wait('Style linespoints') f.set_option(with_='linespoints') g.plot(f) wait('title=None') f.set_option(title=None) g.plot(f) wait('title="Sine of x"') f.set_option(title='Sine of x') g.plot(f) wait('axes=x2y2') f.set_option(axes='x2y2') g.plot(f) print '############### test File ###################################' wait('Generate a File from a filename') g.plot(Gnuplot.File(filename1)) wait('Style lines') g.plot(Gnuplot.File(filename1, with_='lines')) wait('using=1, using=(1,)') g.plot(Gnuplot.File(filename1, using=1, with_='lines'), Gnuplot.File(filename1, using=(1, ), with_='points')) wait('using=(1,2), using="1:3"') g.plot(Gnuplot.File(filename1, using=(1, 2)), Gnuplot.File(filename1, using='1:3')) wait('every=5, every=(5,)') g.plot(Gnuplot.File(filename1, every=5, with_='lines'), Gnuplot.File(filename1, every=(5, ), with_='points')) wait('every=(10,None,0), every="10::5"') g.plot(Gnuplot.File(filename1, with_='lines'), Gnuplot.File(filename1, every=(10, None, 0)), Gnuplot.File(filename1, every='10::5')) wait('title=None') g.plot(Gnuplot.File(filename1, title=None)) wait('title="title"') g.plot(Gnuplot.File(filename1, title='title')) print 'Change File attributes after construction:' f = Gnuplot.File(filename1) wait('Original') g.plot(f) wait('Style linespoints') f.set_option(with_='linespoints') g.plot(f) wait('using=(1,3)') f.set_option(using=(1, 3)) g.plot(f) wait('title=None') f.set_option(title=None) g.plot(f) print '############### test Data ###################################' x = numpy.arange(100) / 5. - 10. y1 = numpy.cos(x) y2 = numpy.sin(x) d = numpy.transpose((x, y1, y2)) wait('Plot Data against its index') g.plot(Gnuplot.Data(y2, inline=0)) wait('Plot Data, specified column-by-column') g.plot(Gnuplot.Data(x, y2, inline=0)) wait('Same thing, saved to a file') Gnuplot.Data(x, y2, inline=0, filename=filename1) g.plot(Gnuplot.File(filename1)) wait('Same thing, inline data') g.plot(Gnuplot.Data(x, y2, inline=1)) wait('Plot Data, specified by an array') g.plot(Gnuplot.Data(d, inline=0)) wait('Same thing, saved to a file') Gnuplot.Data(d, inline=0, filename=filename1) g.plot(Gnuplot.File(filename1)) wait('Same thing, inline data') g.plot(Gnuplot.Data(d, inline=1)) wait('with_="lp 4 4"') g.plot(Gnuplot.Data(d, with_='lp 4 4')) wait('cols=0') g.plot(Gnuplot.Data(d, cols=0)) wait('cols=(0,1), cols=(0,2)') g.plot(Gnuplot.Data(d, cols=(0, 1), inline=0), Gnuplot.Data(d, cols=(0, 2), inline=0)) wait('Same thing, saved to files') Gnuplot.Data(d, cols=(0, 1), inline=0, filename=filename1) Gnuplot.Data(d, cols=(0, 2), inline=0, filename=filename2) g.plot(Gnuplot.File(filename1), Gnuplot.File(filename2)) wait('Same thing, inline data') g.plot(Gnuplot.Data(d, cols=(0, 1), inline=1), Gnuplot.Data(d, cols=(0, 2), inline=1)) wait('Change title and replot()') g.title('New title') g.replot() wait('title=None') g.plot(Gnuplot.Data(d, title=None)) wait('title="Cosine of x"') g.plot(Gnuplot.Data(d, title='Cosine of x')) print '############### test compute_Data ###########################' x = numpy.arange(100) / 5. - 10. wait('Plot Data, computed by Gnuplot.py') g.plot( Gnuplot.funcutils.compute_Data(x, lambda x: math.cos(x), inline=0)) wait('Same thing, saved to a file') Gnuplot.funcutils.compute_Data(x, lambda x: math.cos(x), inline=0, filename=filename1) g.plot(Gnuplot.File(filename1)) wait('Same thing, inline data') g.plot(Gnuplot.funcutils.compute_Data(x, math.cos, inline=1)) wait('with_="lp 4 4"') g.plot(Gnuplot.funcutils.compute_Data(x, math.cos, with_='lp 4 4')) print '############### test hardcopy ###############################' print '******** Generating postscript file "gp_test.ps" ********' wait() g.plot( Gnuplot.Func('cos(0.5*x*x)', with_='linespoints 2 2', title='cos(0.5*x^2)')) g.hardcopy('gp_test.ps') wait('Testing hardcopy options: mode="eps"') g.hardcopy('gp_test.ps', mode='eps') wait('Testing hardcopy options: mode="landscape"') g.hardcopy('gp_test.ps', mode='landscape') wait('Testing hardcopy options: mode="portrait"') g.hardcopy('gp_test.ps', mode='portrait') wait('Testing hardcopy options: eps=1') g.hardcopy('gp_test.ps', eps=1) wait('Testing hardcopy options: mode="default"') g.hardcopy('gp_test.ps', mode='default') wait('Testing hardcopy options: enhanced=1') g.hardcopy('gp_test.ps', enhanced=1) wait('Testing hardcopy options: enhanced=0') g.hardcopy('gp_test.ps', enhanced=0) wait('Testing hardcopy options: color=1') g.hardcopy('gp_test.ps', color=1) # For some reason, # g.hardcopy('gp_test.ps', color=0, solid=1) # doesn't work here (it doesn't activate the solid option), even # though the command sent to gnuplot looks correct. I'll # tentatively conclude that it is a gnuplot bug. ### wait('Testing hardcopy options: color=0') g.hardcopy('gp_test.ps', color=0) wait('Testing hardcopy options: solid=1') g.hardcopy('gp_test.ps', solid=1) wait('Testing hardcopy options: duplexing="duplex"') g.hardcopy('gp_test.ps', solid=0, duplexing='duplex') wait('Testing hardcopy options: duplexing="defaultplex"') g.hardcopy('gp_test.ps', duplexing='defaultplex') wait('Testing hardcopy options: fontname="Times-Italic"') g.hardcopy('gp_test.ps', fontname='Times-Italic') wait('Testing hardcopy options: fontsize=20') g.hardcopy('gp_test.ps', fontsize=20) print '******** Generating svg file "gp_test.svg" ********' wait() g.plot( Gnuplot.Func('cos(0.5*x*x)', with_='linespoints 2 2', title='cos(0.5*x^2)')) g.hardcopy('gp_test.svg', terminal='svg') wait('Testing hardcopy svg options: enhanced') g.hardcopy('gp_test.ps', terminal='svg', enhanced='1') print '############### test shortcuts ##############################' wait('plot Func and Data using shortcuts') g.plot('sin(x)', d) print '############### test splot ##################################' wait('a 3-d curve') g.splot(Gnuplot.Data(d, with_='linesp', inline=0)) wait('Same thing, saved to a file') Gnuplot.Data(d, inline=0, filename=filename1) g.splot(Gnuplot.File(filename1, with_='linesp')) wait('Same thing, inline data') g.splot(Gnuplot.Data(d, with_='linesp', inline=1)) print '############### test GridData and compute_GridData ##########' # set up x and y values at which the function will be tabulated: x = numpy.arange(35) / 2.0 y = numpy.arange(30) / 10.0 - 1.5 # Make a 2-d array containing a function of x and y. First create # xm and ym which contain the x and y values in a matrix form that # can be `broadcast' into a matrix of the appropriate shape: xm = x[:, numpy.newaxis] ym = y[numpy.newaxis, :] m = (numpy.sin(xm) + 0.1 * xm) - ym**2 wait('a function of two variables from a GridData file') g('set parametric') g('set data style lines') g('set hidden') g('set contour base') g.xlabel('x') g.ylabel('y') g.splot(Gnuplot.GridData(m, x, y, binary=0, inline=0)) wait('Same thing, saved to a file') Gnuplot.GridData(m, x, y, binary=0, inline=0, filename=filename1) g.splot(Gnuplot.File(filename1, binary=0)) wait('Same thing, inline data') g.splot(Gnuplot.GridData(m, x, y, binary=0, inline=1)) wait('The same thing using binary mode') g.splot(Gnuplot.GridData(m, x, y, binary=1)) wait('Same thing, using binary mode and an intermediate file') Gnuplot.GridData(m, x, y, binary=1, filename=filename1) g.splot(Gnuplot.File(filename1, binary=1)) wait('The same thing using compute_GridData to tabulate function') g.splot( Gnuplot.funcutils.compute_GridData( x, y, lambda x, y: math.sin(x) + 0.1 * x - y**2, )) wait('Same thing, with an intermediate file') Gnuplot.funcutils.compute_GridData( x, y, lambda x, y: math.sin(x) + 0.1 * x - y**2, filename=filename1) g.splot(Gnuplot.File(filename1, binary=1)) wait('Use compute_GridData in ufunc and binary mode') g.splot( Gnuplot.funcutils.compute_GridData( x, y, lambda x, y: numpy.sin(x) + 0.1 * x - y**2, ufunc=1, binary=1, )) wait('Same thing, with an intermediate file') Gnuplot.funcutils.compute_GridData( x, y, lambda x, y: numpy.sin(x) + 0.1 * x - y**2, ufunc=1, binary=1, filename=filename1) g.splot(Gnuplot.File(filename1, binary=1)) wait('And now rotate it a bit') for view in range(35, 70, 5): g('set view 60, %d' % view) g.replot() time.sleep(1.0) wait(prompt='Press return to end the test.\n') finally: os.unlink(filename1) os.unlink(filename2)
def net_plot(self): if not os.path.exists('./diagrams'): os.makedirs('./diagrams') for my_dom in self.doms_explicit: print("*** Day " + my_dom) # A straightforward use of gnuplot. The `debug=1' switch is used # in these examples so that the commands that are sent to gnuplot # are also output on stderr. plots_ethx_rxkb = [] plots_ethx_txkb = [] plots_vif_rxkb = [] plots_vif_txkb = [] plots_vlan_rxkb = [] plots_vlan_txkb = [] for my_nic in self.nic_names[my_dom]: if my_nic.startswith("eth"): plots_ethx_rxkb.append( Gnuplot.File("./results/" + self.host + "-" + my_dom + "-nic-" + my_nic + ".csv", using="1:5", with_="lines", title=my_nic)) plots_ethx_txkb.append( Gnuplot.File("./results/" + self.host + "-" + my_dom + "-nic-" + my_nic + ".csv", using="1:6", with_="lines", title=my_nic)) elif my_nic.startswith("vlan"): plots_vlan_rxkb.append( Gnuplot.File("./results/" + self.host + "-" + my_dom + "-nic-" + my_nic + ".csv", using="1:5", with_="lines", title=my_nic)) plots_vlan_txkb.append( Gnuplot.File("./results/" + self.host + "-" + my_dom + "-nic-" + my_nic + ".csv", using="1:6", with_="lines", title=my_nic)) elif my_nic != "br0" and my_nic != "lo" and my_nic != "ovs-system": plots_vif_rxkb.append( Gnuplot.File("./results/" + self.host + "-" + my_dom + "-nic-" + my_nic + ".csv", using="1:5", with_="lines", title=my_nic)) plots_vif_txkb.append( Gnuplot.File("./results/" + self.host + "-" + my_dom + "-nic-" + my_nic + ".csv", using="1:6", with_="lines", title=my_nic)) # g.plot(Gnuplot.File("./results/hera-" + my_dom + "-nic-" + "eth0" + ".csv", using="1:5"), # Gnuplot.File("./results/hera-" + my_dom + "-nic-" + "eth1" + # ".csv", using="1:5")) g = Gnuplot.Gnuplot(debug=1) g('set terminal pngcairo size 1750,875 enhanced font \'Verdana,8\'') g('set output \'./diagrams/' + self.host + "-" + my_dom + '-nic.png\'') # g('set style data linespoints') # give gnuplot an arbitrary # command g('set format x "%H:%M"') g('set timefmt "%H:%M:%S"') g('set xdata time') g('set multiplot layout 3, 2') g("set decimalsign ','") g.title('Network Received KB/s') # (optional) g.plot(*plots_ethx_rxkb) g.title('Network Received KB/s') # (optional) g.plot(*plots_ethx_txkb) g.title('Network Received KB/s') # (optional) g.plot(*plots_vlan_rxkb) g.title('Network Transmited KB/s') # (optional) g.plot(*plots_vlan_txkb) g.title('Network Transmited KB/s') # (optional) g.plot(*plots_vif_rxkb) g.title('Network Transmited KB/s') # (optional) g.plot(*plots_vif_txkb) g('set nomultiplot')
y = float(s[1]) yMin = min(yMin, y) yMax = max(yMax, y) z = float(s[2]) zMin = min(zMin, z) zMax = max(zMax, z) s = "%15.7e %15.7e %15.7e\n" % (x, y, z) f.write(s) f.close() g = Gnuplot.Gnuplot() g('set style data lines') g('set ticslevel 0.') g("set nokey") if (filesToPlot): d = Gnuplot.File(f.getName()) xlog = 0 ylog = 0 zlog = 0 xMinStr = "*" xMaxStr = "*" yMinStr = "*" yMaxStr = "*" zMinStr = "*" zMaxStr = "*" xLabel = "x" yLabel = "y" zLabel = "z" Title = "" xrot = 60
xMin = min(xMin, x) xMax = max(xMax, x) y = float(s[1]) yMin = min(yMin, y) yMax = max(yMax, y) xMin, xMax = adjustRange(xMin, xMax) yMin, yMax = adjustRange(yMin, yMax) Options['xMin'] = xMin Options['xMax'] = xMax Options['yMin'] = yMin Options['yMax'] = yMax g = Gnuplot.Gnuplot() g('set ticslevel 0.') g("set nokey") if (filesToPlot): d = Gnuplot.File(InputFileName) DoDelete = 0 i = 1 n = len(sys.argv) - 1 while (i < n): inc = 2 if (sys.argv[i] == "delete"): inc = 1 DoDelete = 1 elif (sys.argv[i] in Options): Options[sys.argv[i]] = sys.argv[i + 1].strip('"') else: print print "Invalid option = <%s>" % sys.argv[i] print