import mympltools as util import numpy as np import matplotlib.pyplot as plt style.use('dippa3D') d=loadmat('harmonic_3D.mat') keys = ('lh_em_n','est_em_n','lh_bfgs_n','est_bfgs_n') colors = ('#348ABD','#E24A33') labels = ('$\sigma_\omega$','$\sigma_x$','$\ell$') w = 426.79134/72.27 #h = w #fig = plt.figure(figsize=(w,2*w),facecolor='w') zllim = 1.5e4 for j in range(2): fig,ax = util.getpadfigure(figw=w/1.2,figh=w/1.2,is3D=True) #fig = plt.figure(figsize=(w,w),facecolor='w') #ax = fig.add_subplot(111,projection='3d') lh = d[keys[j*2]] est = d[keys[j*2+1]] for k in range(100): zi = lh[:,k]>zllim ax.plot(est[0,zi,k],est[1,zi,k],lh[zi,k], alpha=0.5, color=colors[j], lw=0.9, marker=None, markersize=3) ax.plot(est[0,-1,:],est[1,-1,:],lh[-1,:], alpha=0.7, color=colors[j],
def draw(dataFileName): A = np.array # shortcut style.use('dippa') cycle = plt.rcParams["axes.color_cycle"] defc = ['b', 'g', 'r', 'c', 'm', 'y', 'k'] inp = loadmat(dataFileName,squeeze_me=True,struct_as_record=False) try: xlabel = inp["xlabel"] except KeyError as e: xlabel = None try: ylabel = inp["ylabel"] except KeyError as e: ylabel = None try: title = inp["title"] except KeyError as e: title = None try: legend = inp["legend"] except KeyError as e: legend = None try: legendkw = _todict(inp["legendkw"]) except KeyError as e: legendkw = {} try: w = inp["w"] except KeyError as e: w = 5 try: margins = {'margins': inp["margins"]} except KeyError as e: margins = {} try: margins['figh'] = inp["h"] except KeyError: pass try: alpha = inp["alpha"] except KeyError as e: alpha = 0.05 try: axlim = inp["axis"] except KeyError as e: axlim = None try: ticklabels = inp["ticklabels"] except KeyError as e: ticklabels = None fig,ax = util.getpadfigure(w,**margins) # plot lines = [] for k,triplet in enumerate(inp["data"]): if len(triplet) < 2: continue if len(triplet) > 2 and type(triplet[2]) is not unicode: triplet[2] = "" arg = triplet[0:3] #print(arg) kw = _setcolor(triplet,cycle,defc,k) lines.append(ax.plot(*arg,**kw)[0]) #print(kw) #if kw.has_key("yerr"): # kw["ax"] = ax # errorfill(arg[0],arg[1],**kw) #else: # ax.plot(*arg,**kw) ax.hold(True) util.padaxis(ax,alpha,l=axlim) if title is not None: ax.set_title(title,family='serif') if xlabel is not None: xlabel = ax.set_xlabel(xlabel,family='serif') if ylabel is not None: ylabel = ax.set_ylabel(ylabel,family='serif') if legend is not None: #print(legend) #print(lines) lg = ax.legend(lines,legend.flat,**legendkw) # if xlabel is not None: # for text in lg.get_texts(): # text.set_color(xlabel.get_color()) for text in lg.get_texts(): text.set_family('serif') if ticklabels is not None: if not ticklabels[0]: ax.set_xticklabels([]) if not ticklabels[1]: ax.set_yticklabels([]) return(ax)
def draw(dataFileName): A = np.array # shortcut style.use("dippa") cycle = plt.rcParams["axes.color_cycle"] defc = ["b", "g", "r", "c", "m", "y", "k"] inp = loadmat(dataFileName, squeeze_me=True, struct_as_record=False) try: xlabel = inp["xlabel"] except KeyError as e: xlabel = None try: ylabel = inp["ylabel"] except KeyError as e: ylabel = None try: title = inp["title"] except KeyError as e: title = None try: legend = inp["legend"] except KeyError as e: legend = None try: legendkw = _todict(inp["legendkw"]) except KeyError as e: legendkw = {} try: w = inp["w"] except KeyError as e: w = 5 try: margins = {"margins": inp["margins"]} except KeyError as e: margins = {} try: margins["figh"] = inp["h"] except KeyError: pass try: alpha = inp["alpha"] except KeyError as e: alpha = 0.05 try: axlim = inp["axis"] except KeyError as e: axlim = None try: ticklabels = inp["ticklabels"] except KeyError as e: ticklabels = None fig, ax = util.getpadfigure(w, **margins) # plot lines = [] for k, triplet in enumerate(inp["data"]): if len(triplet) < 2: continue if len(triplet) > 2 and type(triplet[2]) is not unicode: triplet[2] = "" arg = triplet[0:3] # print(arg) kw = _setcolor(triplet, cycle, defc, k) lines.append(ax.plot(*arg, **kw)[0]) # print(kw) # if kw.has_key("yerr"): # kw["ax"] = ax # errorfill(arg[0],arg[1],**kw) # else: # ax.plot(*arg,**kw) ax.hold(True) util.padaxis(ax, alpha, l=axlim) if title is not None: ax.set_title(title, family="serif") if xlabel is not None: xlabel = ax.set_xlabel(xlabel, family="serif") if ylabel is not None: ylabel = ax.set_ylabel(ylabel, family="serif") if legend is not None: # print(legend) # print(lines) lg = ax.legend(lines, legend.flat, **legendkw) # if xlabel is not None: # for text in lg.get_texts(): # text.set_color(xlabel.get_color()) for text in lg.get_texts(): text.set_family("serif") if ticklabels is not None: if not ticklabels[0]: ax.set_xticklabels([]) if not ticklabels[1]: ax.set_yticklabels([]) return ax