def compplot_deviations(jsonfilelist, fignum=333, figname="figdiff", compress=10): """ compute the deviations of the measured output from the stable state output """ import matplotlib.cm as cm fig = plt.figure(fignum) ax1 = fig.add_subplot(111) diffnormlist = [] collin = np.linspace(0.2, 0.7, len(jsonfilelist)) for k, jsfstr in enumerate(jsonfilelist): jsf = dou.load_json_dicts(jsfstr) tmesh = jsf["tmesh"] redinds = range(0, len(tmesh), compress) redina = np.array(redinds) outsig = np.array(jsf["outsig"]) # two norm at the differences outsigdiff = np.sqrt(((outsig - outsig[0, :]) * (outsig - outsig[0, :])).sum(axis=1)) diffnormlist.append((tmesh[-1] - tmesh[0]) / len(tmesh) * outsigdiff.sum()) curline, = ax1.plot( np.array(tmesh)[redina], outsigdiff[redina], c=cm.CMRmap(collin[k]), linewidth=2.0, label="{0}".format(k) ) handles, labels = ax1.get_legend_handles_labels() ax1.legend(handles, labels, loc="lower right") tikz_save(figname + "{0}".format(fignum) + ".tikz", figureheight="\\figureheight", figurewidth="\\figurewidth") print "saved to " + figname + "{0}".format(fignum) + ".tikz" fig.show() print diffnormlist print len(tmesh)
def compplotfreqresps(jsonfilelist, fignum=444, figname="freqfigdiff", compress=1): """ plot the errors in the freqresp for various configurations Parameters: ----------- jsonfilelist : list of json files as produced by `btu.compare_freqresp` """ import matplotlib.cm as cm fig = plt.figure(fignum) ax1 = fig.add_subplot(111) collin = np.linspace(0.2, 0.7, len(jsonfilelist)) for k, jsfstr in enumerate(jsonfilelist): jsf = dou.load_json_dicts(jsfstr) tmesh = jsf["tmesh"] redinds = range(0, len(tmesh), compress) redina = np.array(redinds) outsig = np.array(jsf["diffsysfr"]) curline, = ax1.plot( np.array(tmesh)[redina], outsig[redina], c=cm.CMRmap(collin[k]), linewidth=2.0, label="{0}".format(k) ) handles, labels = ax1.get_legend_handles_labels() ax1.legend(handles, labels, loc="lower left") tikz_save(figname + "{0}".format(fignum) + ".tikz", figureheight="\\figureheight", figurewidth="\\figurewidth") print "saved to " + figname + "{0}".format(fignum) + ".tikz" ax1.semilogx() ax1.semilogy() fig.show()
def plot_step_resp(str_to_json=None, tmesh=None, red_stp_rsp=None, ful_stp_rsp=None, inivout=None, compress=20): """ compress : real, optional factor of compressing for plot, defaults to 20 """ from matplotlib2tikz import save as tikz_save if str_to_json is not None: jsdict = dou.load_json_dicts(str_to_json) tmesh = np.array(jsdict['tmesh']) red_stp_rsp = jsdict['red_stp_rsp'] ful_stp_rsp = jsdict['ful_stp_rsp'] inivout = jsdict['inivout'] else: str_to_json = 'notspecified' redinds = list(range(0, len(tmesh), compress)) redina = np.array(redinds) for ccol in range(len(red_stp_rsp)): # [0, b_mat.shape[1]-1]: # range(2): # b_mat.shape[1]): fuloutp = np.array(ful_stp_rsp[ccol]) - np.array(inivout).T redoutp = np.array(red_stp_rsp[ccol]) outdiff = fuloutp - redoutp NY = fuloutp.shape[1] / 2 fig = plt.figure(200 + ccol) ax1 = fig.add_subplot(131) ax1.plot(tmesh[redina], redoutp[redina, :NY], color='b', linewidth=2.0) ax1.plot(tmesh[redina], redoutp[redina, NY:], color='r', linewidth=2.0) ax2 = fig.add_subplot(132) ax2.plot(tmesh[redina], fuloutp[redina, :NY], color='b', linewidth=2.0) ax2.plot(tmesh[redina], fuloutp[redina, NY:], color='r', linewidth=2.0) ax3 = fig.add_subplot(133) ax3.plot(tmesh[redina], outdiff[redina, :NY], color='b', linewidth=2.0) ax3.plot(tmesh[redina], outdiff[redina, NY:], color='r', linewidth=2.0) tikz_save(str_to_json + '{0}'.format(200 + ccol) + '.tikz', figureheight='\\figureheight', figurewidth='\\figurewidth') print('saved to ' + str_to_json + '{0}'.format(200 + ccol) + '.tikz') fig.show()
def plot_step_resp(str_to_json=None, tmesh=None, red_stp_rsp=None, ful_stp_rsp=None, inivout=None, compress=20): """ compress : real, optional factor of compressing for plot, defaults to 20 """ from matplotlib2tikz import save as tikz_save if str_to_json is not None: jsdict = dou.load_json_dicts(str_to_json) tmesh = np.array(jsdict['tmesh']) red_stp_rsp = jsdict['red_stp_rsp'] ful_stp_rsp = jsdict['ful_stp_rsp'] inivout = jsdict['inivout'] else: str_to_json = 'notspecified' redinds = list(range(0, len(tmesh), compress)) redina = np.array(redinds) for ccol in range(len(red_stp_rsp)): # [0, b_mat.shape[1]-1]: # range(2): # b_mat.shape[1]): fuloutp = np.array(ful_stp_rsp[ccol])-np.array(inivout).T redoutp = np.array(red_stp_rsp[ccol]) outdiff = fuloutp - redoutp NY = fuloutp.shape[1]/2 fig = plt.figure(200 + ccol) ax1 = fig.add_subplot(131) ax1.plot(tmesh[redina], redoutp[redina, :NY], color='b', linewidth=2.0) ax1.plot(tmesh[redina], redoutp[redina, NY:], color='r', linewidth=2.0) ax2 = fig.add_subplot(132) ax2.plot(tmesh[redina], fuloutp[redina, :NY], color='b', linewidth=2.0) ax2.plot(tmesh[redina], fuloutp[redina, NY:], color='r', linewidth=2.0) ax3 = fig.add_subplot(133) ax3.plot(tmesh[redina], outdiff[redina, :NY], color='b', linewidth=2.0) ax3.plot(tmesh[redina], outdiff[redina, NY:], color='r', linewidth=2.0) tikz_save(str_to_json + '{0}'.format(200+ccol) + '.tikz', figureheight='\\figureheight', figurewidth='\\figurewidth' ) print('saved to ' + str_to_json + '{0}'.format(200+ccol) + '.tikz') fig.show()