def test_sesolver(): s0, sx, sy, sz = pauli() H = (-0.05) * sz - 0. * sx solver = SESolver(H) Nt = 1000 dt = 4 psi0 = (basis(2, 0) + basis(2, 1)) / np.sqrt(2) start_time = time.time() result = solver.evolve(psi0, dt=dt, Nt=Nt, e_ops=[sx]) print("--- %s seconds ---" % (time.time() - start_time)) start_time = time.time() times = np.arange(Nt) * dt r = _ode_solver(H, psi0, dt=dt, Nt=Nt, nout=2, e_ops=[sx]) print("--- %s seconds ---" % (time.time() - start_time)) # test correlation functions # corr = solver.correlation_3p_1t(psi0=psi0, oplist=[s0, sx, sx], # dt=0.05, Nt=Nt) # # times = np.arange(Nt) # import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot(times, result.observables[:, 0]) ax.plot(r.times, r.observables[:, 0], '--') # ax.plot(times, corr.real) plt.show()
def test_etpa(): epp = Biphoton(0, 0.04 / au2ev, Te=10. / au2fs) p = np.linspace(-4, 4, 256) / au2ev q = p epp.set_grid(p, q) epp.get_jsa() # epp.plt_jsa() pump = np.linspace(0.5, 1.5, 100) / au2ev signal = etpa(pump, mol, epp, [0], [1, 2, 3], [2, 3]) fig, ax = subplots() ax.plot(pump * au2ev, np.abs(signal)**2) plt.show() return
def plot_stats(data, x_key, x_label=None, y_keys=None, y_labels=None, start_index=0, save_filename=None): """ Generate time-series plots of stats specified by keys Args: data: [dict] containing data to be plotted. len of all values should be equal data must include x_key as a valid key x_key: [str] key for the x-axis (time varying component) x_label: [str] corresponding label for the x_key, if not provided then the key is used y_keys: [list of str] optional list of keys to plot, each should exist in data.keys() If nothing is given, data.keys() will be used y_labels: [list of str] optional list of labels, should be the same length as keys input If nothing is given, y_keys will be used start_index: [int] time offset for plotting data - default=0 will plot all data save_filename: [str] containing the complete output filename. Returns: fig: matplotlib figure handle """ assert x_key in list(data.keys()), ('x_key=%s must be in data.keys()' % x_key) if x_label is None: x_label = x_key if y_keys is None: y_keys = list(data.keys()) if 'epoch' in y_keys: y_keys.remove('epoch') if 'batch_step' in y_keys: y_keys.remove('batch_step') else: assert all([y_key in list(data.keys()) for y_key in y_keys]) if y_labels is None: y_labels = [' '.join(y_key.split('_')) for y_key in y_keys] else: assert len(y_labels) == len(y_keys), ( 'The number of y_labels must match the number of y_keys') num_y_keys = len(y_keys) num_plots_y = int(np.ceil(np.sqrt(num_y_keys))) num_plots_x = int(np.ceil(np.sqrt(num_y_keys))) fig, axes = plot.subplots(nrows=num_plots_y, ncols=num_plots_x, sharex=False, sharey=False) key_idx = 0 for plot_id in np.ndindex((num_plots_y, num_plots_x)): if key_idx < num_y_keys: x_dat = data[x_key][start_index:] y_dat = data[y_keys[key_idx]][start_index:] if len(x_dat) == len(y_dat): ax = axes[plot_id] ax.plot(x_dat, y_dat) ax.format(yticks=[ np.minimum(0.0, np.min(y_dat)), np.maximum(0.0, np.max(y_dat)) ], ylabel=y_labels[key_idx]) key_idx += 1 else: ax = clear_axis(axes[plot_id]) print( 'utils/plot_functions.py: WARNING: x and y for key %s must have same first dimensions but are %g and %g' % (y_keys[key_idx], len(x_dat), len(y_dat))) else: ax = clear_axis(axes[plot_id]) axes.format(xlabel=x_label, suptitle='Stats per Batch') if save_filename is not None: fig.savefig(save_filename, transparent=True) plot.close(fig) return None plot.show() return fig
print(i, d) # fit curve popt, _ = scy.curve_fit(objective, d['x'], d['y']) xx = np.linspace(0, 10, 100) yy = [objective(j, popt[0], popt[1], popt[2]) for j in xx] fig = pplt.figure(share=False) ax = fig.subplot(title='Alternate y twin x') ax.plot(d) ax.plot(d) # # ax.set(xlim=(0, 10), ylim=(0, 150)) ax.set(xlabel="U [m/s]", ylabel='$\Delta$P [Pa]') # Put the legend out of the figure pplt.legend() #plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) pplt.tight_layout() # plt.text(0.5, 0.5, 'matplotlib', horizontalalignment='center', verticalalignment='center', transform=ax.transAxes) pplt.savefig("Darcy_Forchheimer_Fit_pplot.pdf") pplt.savefig("Darcy_Forchheimer_Fit_pplot.png", dpi=600) pplt.show()