import numpy as np import nicenquickplotlib as nq x = [] x.append(np.linspace(0,6)) x.append(np.linspace(0,5)) x.append(np.linspace(0,4)) nq.set_figstyle('default') nq.plot(x, [np.sin(x[0]), np.cos(x[1]), np.sqrt(x[2])], legend=[r'$\sin(x)$', r'$\cos(x)$', r'$\sqrt{x}$'], xlabel='x label', ylabel='y label') nq.set_figstyle('blacknwhite') nq.plot(x, [np.sin(x[0]), np.cos(x[1]), np.sqrt(x[2])], legend=[r'$\sin(x)$', r'$\cos(x)$', r'$\sqrt{x}$'], xlabel='x label', ylabel='y label') nq.set_figstyle('soft') nq.plot(x, [np.sin(x[0]), np.cos(x[1]), np.sqrt(x[2])], legend=[r'$\sin(x)$', r'$\cos(x)$', r'$\sqrt{x}$'], xlabel='x label', ylabel='y label') nq.set_figstyle('my_figstyle.yaml') nq.plot(x, [np.sin(x[0]), np.cos(x[1]), np.sqrt(x[2])], legend=[r'$\sin(x)$', r'$\cos(x)$', r'$\sqrt{x}$'], xlabel='x label', ylabel='y label') nq.save_all()
for k in range(len(DMM)): DMM[k].write('RESET') FunGen.write('RESET') print('Instruments have been reset.') for k in range(len(DMM)): DMM[k].read_termination = HP3458A.read_termination FunGen.read_termination = HP3458A.read_termination # Measure -------------------------------------------------------------- for k in range(len(GENERATOR_FREQUENCIES)): timestamp = utils.timestamp.generate_timestamp() samples, sampling_frequency = measure_burst(FunGen=FunGen, DMM=DMM, generator_frequency=GENERATOR_FREQUENCIES[k], generator_amplitude=GENERATOR_AMPLITUDE, sampling_frequency=SAMPLING_FREQUENCIES[k], number_of_samples=SAMPLES_PER_BURST, verbose=True) with open(DIRS.UNPROCESSED_DATA_PATH + timestamp + DIRS.CONFIG_FILE_SUFFIX, 'w') as ofile: print('Generator frequency (Hz)\tSampling frequency (Hz)\tGenerator amplitude (V)', file=ofile) print(str(GENERATOR_FREQUENCIES[k]) + '\t' + str(sampling_frequency) + '\t' + str(GENERATOR_AMPLITUDE), file=ofile) with open(DIRS.UNPROCESSED_DATA_PATH + timestamp + DIRS.SAMPLES_FILE_SUFFIX, 'w') as ofile: print('Samples1 (V)\tSamples2 (V)', file=ofile) for k in range(len(samples[0])): print(str(samples[0][k].n) + '\t' + str(samples[1][k].n), file=ofile) # Close instruments ---------------------------------------------------- print('Closing instruments...') for k in range(len(DMM)): DMM[k].write('DISP OFF, \'I am DMM[' + str(k) + ']\'') DMM[k].close() FunGen.write('USE CHANA') # Select channel A to receive subsequent commands. FunGen.write('TERM OFF') # Disconnect the output from all terminals. FunGen.write('USE CHANB') # Select channel B to receive subsequent commands. FunGen.write('TERM OFF') # Disconnect the output from all terminals. FunGen.close() print('Saving data...') nq.save_all(timestamp=True, csv=True)
legend=r'$\sin (x)$', title='legend passing the legend as a string') nq.plot(x[0], np.sin(x[0]), legend=[r'$\sin (x)$'], title='legend passing the legend as a list') nq.plot(x, [np.sin(x[0]), np.cos(x[1]), np.sqrt(x[2])], legend=[r'$\sin(x)$', r'$\cos(x)$', r'$\sqrt{x}$'], title='legend multiple legends together') nq.plot(x, [np.sin(x[0]), np.cos(x[1]), np.sqrt(x[2])], legend=[r'$\sin(x)$', r'$\cos(x)$', r'$\sqrt{x}$'], together=False, title='legend multiple legends together=False') nq.save_all(timestamp='now') # Test colors ----------------------------- random_y = [] for k in range(10): random_y.append(np.random.normal(loc=k, size=10)) nq.set_figstyle('default') nq.plot(random_y, title='colors') # Test markers ---------------------------- nq.plot(x, [np.sin(x[0]), np.cos(x[1]), np.sqrt(x[2])], legend=[r'$\sin(x)$', r'$\cos(x)$', r'$\sqrt{x}$'], marker=True, title='markers default') nq.plot(x, [np.sin(x[0]), np.cos(x[1]), np.sqrt(x[2])], legend=[r'$\sin(x)$', r'$\cos(x)$', r'$\sqrt{x}$'],
import nicenquickplotlib as nq import uncertainties as unc # https://pythonhosted.org/uncertainties/index.html import numpy as np x = np.linspace(0, 2, 10) # Create x data. y_vals_1 = x**2 # Create y_1 data. y_errs_1 = y_vals_1 * 0.1 + np.random.rand(len(x)) * 0.1 # Create y_1 errors. y_vals_2 = np.sqrt(x) # Create y_2 data. y_errs_2 = y_vals_2 * 0.1 + np.random.rand(len(x)) * 0.1 # Create y_2 errors. y_1 = unc.unumpy.uarray(y_vals_1, y_errs_1) # Create y_1 array of uncertainties. y_2 = unc.unumpy.uarray(y_vals_2, y_errs_2) # Create y_2 array of uncertainties. nq.plot(x, [y_1, y_2], title='y error bands', legend=['Data 1', 'Data 2'], marker=True) nq.set_figstyle('blacknwhite') nq.plot(x, [y_1, y_2], title='y error bands with blacknwhite figstyle', legend=['Data 1', 'Data 2'], marker=True) nq.save_all(csv=True)
freq = np.array(freq) # PLOT ---------------------------- nq.plot(x=freq, y=[T_abs_definitive, T_phi_definitive], together=False, xlabel='Frequency (Hz)', ylabel=['Ratio', 'Phase (rad)'], xscale='L', title='Transference', marker='.') nq.plot( x=freq, y=[ unp.std_devs(T_abs_definitive) / unp.nominal_values(T_abs_definitive), np.abs( unp.std_devs(T_phi_definitive) / unp.nominal_values(T_phi_definitive)) ], together=False, xlabel='Frequency (Hz)', ylabel=[ r'Ratio err $\frac{\sigma}{\mu}$', r'Phase err $\frac{\sigma}{\mu}$' ], xscale='L', yscale='L', title='Transference uncertainties', marker='.') nq.save_all(mkdir=DIRS.TRANSFERENCE_RESULTS_PATH, csv=True) print('Transference has been plotted and data was saved in ' + DIRS.TRANSFERENCE_RESULTS_PATH)
ylabel='Voltage (V)', nicebox=True, marker='.') fig.axes[-1].set_xlim( [0, 10 * sampling_frequency / 2 / np.pi / generator_frequency]) # Transference calculation --------------- T_abs = discrete_time_model[1].param_val(0) / discrete_time_model[0].param_val( 0) T_phi = utils.lock_in_process.lock_in_process(samples[0], samples[1]) T_abs = np.abs( T_abs ) # This is because sometimes the fitting algorithm converges to a negative amplitude. # Save data ------------------------------ os.rename( DIRS.CURRENTLY_PROCESSING_DATA_PATH + current_timestamp + DIRS.CONFIG_FILE_SUFFIX, DIRS.PROCESSED_DATA_PATH + current_timestamp + DIRS.CONFIG_FILE_SUFFIX) os.rename( DIRS.CURRENTLY_PROCESSING_DATA_PATH + current_timestamp + DIRS.SAMPLES_FILE_SUFFIX, DIRS.PROCESSED_DATA_PATH + current_timestamp + DIRS.SAMPLES_FILE_SUFFIX) nq.save_all(mkdir=DIRS.PROCESSED_DATA_PATH + current_timestamp + 'plots') with open( DIRS.PROCESSED_DATA_PATH + current_timestamp + DIRS.TRANSFERENCE_FILE_SUFFIX, 'w') as ofile: print('T_abs.n\tT_abs.s\tT_phi.n', file=ofile) print(str(T_abs.n) + '\t' + str(T_abs.s) + '\t' + str(T_phi), file=ofile) print('Analysis completed.') print('Original data and results can be found in "' + DIRS.PROCESSED_DATA_PATH + '"')
fungen.write('OUTP1:IMP INF' ) # Set the output impedance to zero (infinite load impedance). fungen.write('voltage {}'.format(GENERATOR_AMPLITUDE)) fungen.write('voltage:offset {}'.format(GENERATOR_AMPLITUDE / 2)) fungen.write(':frequency:fixed {}'.format( GENERATOR_FREQUENCY)) #sets function generator frequency fungen.write('source1:function:shape squ') little_board = cf.Little_Board('Dev11') fungen.write('OUTP1:STAT ON') time.sleep(1) data = np.array( little_board.acquire(n_samples=N_SAMPLES, sampling_frequency=GENERATOR_FREQUENCY * N_SAMPLES / N_CYCLES, ch0=True, ch1=True)) time_axis = np.linspace(0, N_CYCLES / GENERATOR_FREQUENCY, N_SAMPLES) nq.plot(x=time_axis, y=[np.array(data[0]), np.array(data[1])], together=False, xlabel='Tiempo (s)') fungen.write('OUTP1:STAT OFF') fungen.close() nq.save_all(timestamp=True, image_format='pdf', csv=True) nq.show()
import numpy as np import nicenquickplotlib as nq x = [] x.append(np.linspace(0, 6)) x.append(np.linspace(0, 5)) x.append(np.linspace(0, 4)) nq.set_figstyle('default') nq.plot(x, [np.sin(x[0]), np.cos(x[1]), np.sqrt(x[2])], legend=[r'$\sin(x)$', r'$\cos(x)$', r'$\sqrt{x}$'], xlabel='x label', ylabel='y label') nq.set_figstyle('blacknwhite') nq.plot(x, [np.sin(x[0]), np.cos(x[1]), np.sqrt(x[2])], legend=[r'$\sin(x)$', r'$\cos(x)$', r'$\sqrt{x}$'], xlabel='x label', ylabel='y label') nq.set_figstyle('soft') nq.plot(x, [np.sin(x[0]), np.cos(x[1]), np.sqrt(x[2])], legend=[r'$\sin(x)$', r'$\cos(x)$', r'$\sqrt{x}$'], xlabel='x label', ylabel='y label') nq.save_all(image_format='pdf')