def plot_L(self): fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) for el in self.L: self.plot_box(X=el, index=0, this_color='blue', canvas=ax) ax.set_xlim(-15., 15.) ax.set_ylim(-15., 15.) ax.axis('equal') plt.show()
def renderGraph(self): # pylint: disable=R0914 assert len(self._oData.aoSeries) == 1 oSeries = self._oData.aoSeries[0] # hacking #self.setWidth(512); #self.setHeight(128); # end oFigure = self._createFigure() from mpl_toolkits.axes_grid.axislines import SubplotZero # pylint: disable=E0401 oAxis = SubplotZero(oFigure, 111) oFigure.add_subplot(oAxis) # Disable all the normal axis. oAxis.axis['right'].set_visible(False) oAxis.axis['top'].set_visible(False) oAxis.axis['bottom'].set_visible(False) oAxis.axis['left'].set_visible(False) # Use the zero axis instead. oAxis.axis['yzero'].set_axisline_style('-|>') oAxis.axis['yzero'].set_visible(True) oAxis.axis['xzero'].set_axisline_style('-|>') oAxis.axis['xzero'].set_visible(True) if oSeries.aoYValues[-1] == 100: sColor = 'green' elif oSeries.aoYValues[-1] > 75: sColor = 'yellow' else: sColor = 'red' oAxis.plot(oSeries.aoXValues, oSeries.aoYValues, '.-', color=sColor, linewidth=3) oAxis.fill_between(oSeries.aoXValues, oSeries.aoYValues, facecolor=sColor, alpha=0.5) oAxis.set_xlim(left=-0.01) oAxis.set_xticklabels([]) oAxis.set_xmargin(1) oAxis.set_ylim(bottom=0, top=100) oAxis.set_yticks([0, 50, 100]) oAxis.set_ylabel('%') #oAxis.set_yticklabels([]); oAxis.set_yticklabels(['', '%', '']) return self._produceSvg(oFigure, False)
def plot_subpaving(self): fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) for el in self.outside: self.plot_box(X=el, index=0, this_color='red', canvas=ax) for el in self.boundary: self.plot_box(X=el, index=0, this_color='yellow', canvas=ax) for el in self.inside: self.plot_box(X=el, index=0, this_color='green', canvas=ax) ax.set_xlim(-12., 12.) ax.set_ylim(-12., 12.) ax.axis('equal') plt.show() return
def renderGraph(self): # pylint: disable=R0914 assert len(self._oData.aoSeries) == 1 oSeries = self._oData.aoSeries[0] # hacking # self.setWidth(512); # self.setHeight(128); # end oFigure = self._createFigure() from mpl_toolkits.axes_grid.axislines import SubplotZero # pylint: disable=E0401 oAxis = SubplotZero(oFigure, 111) oFigure.add_subplot(oAxis) # Disable all the normal axis. oAxis.axis["right"].set_visible(False) oAxis.axis["top"].set_visible(False) oAxis.axis["bottom"].set_visible(False) oAxis.axis["left"].set_visible(False) # Use the zero axis instead. oAxis.axis["yzero"].set_axisline_style("-|>") oAxis.axis["yzero"].set_visible(True) oAxis.axis["xzero"].set_axisline_style("-|>") oAxis.axis["xzero"].set_visible(True) if oSeries.aoYValues[-1] == 100: sColor = "green" elif oSeries.aoYValues[-1] > 75: sColor = "yellow" else: sColor = "red" oAxis.plot(oSeries.aoXValues, oSeries.aoYValues, ".-", color=sColor, linewidth=3) oAxis.fill_between(oSeries.aoXValues, oSeries.aoYValues, facecolor=sColor, alpha=0.5) oAxis.set_xlim(left=-0.01) oAxis.set_xticklabels([]) oAxis.set_xmargin(1) oAxis.set_ylim(bottom=0, top=100) oAxis.set_yticks([0, 50, 100]) oAxis.set_ylabel("%") # oAxis.set_yticklabels([]); oAxis.set_yticklabels(["", "%", ""]) return self._produceSvg(oFigure, False)
def initplot(size): """ Inicializa o desenho de gráficos. """ fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) for direction in ["xzero", "yzero"]: ax.axis[direction].set_axisline_style("-|>") ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: ax.axis[direction].set_visible(False) ax.set_xlim(-10, size) ax.set_ylim(-10, size) return (fig, ax)
def renderGraph(self): # pylint: disable=R0914 assert len(self._oData.aoSeries) == 1; oSeries = self._oData.aoSeries[0]; # hacking #self.setWidth(512); #self.setHeight(128); # end oFigure = self._createFigure(); from mpl_toolkits.axes_grid.axislines import SubplotZero; oAxis = SubplotZero(oFigure, 111); oFigure.add_subplot(oAxis); # Disable all the normal axis. oAxis.axis['right'].set_visible(False) oAxis.axis['top'].set_visible(False) oAxis.axis['bottom'].set_visible(False) oAxis.axis['left'].set_visible(False) # Use the zero axis instead. oAxis.axis['yzero'].set_axisline_style('-|>'); oAxis.axis['yzero'].set_visible(True); oAxis.axis['xzero'].set_axisline_style('-|>'); oAxis.axis['xzero'].set_visible(True); if oSeries.aoYValues[-1] == 100: sColor = 'green'; elif oSeries.aoYValues[-1] > 75: sColor = 'yellow'; else: sColor = 'red'; oAxis.plot(oSeries.aoXValues, oSeries.aoYValues, '.-', color = sColor, linewidth = 3); oAxis.fill_between(oSeries.aoXValues, oSeries.aoYValues, facecolor = sColor, alpha = 0.5) oAxis.set_xlim(left = -0.01); oAxis.set_xticklabels([]); oAxis.set_xmargin(1); oAxis.set_ylim(bottom = 0, top = 100); oAxis.set_yticks([0, 50, 100]); oAxis.set_ylabel('%'); #oAxis.set_yticklabels([]); oAxis.set_yticklabels(['', '%', '']); return self._produceSvg(oFigure, False);
def draw_graph(self): min_time = 0 max_time = 0 for val in self.readings: if min_time == 0: min_time = val["time"] if val["time"] < min_time: min_time = val["time"] if max_time == 0: max_time = val["time"] if val["time"] > max_time: max_time = val["time"] fig = plt.figure(1) fig.subplots_adjust(right=0.85) ax = SubplotZero(fig, 1, 1, 1) fig.add_subplot(ax) plt.title("Score for Game: %s" % self.score) # make right and top axis invisible ax.axis["right"].set_visible(False) ax.axis["top"].set_visible(False) # make xzero axis (horizontal axis line through y=0) visible. ax.axis["xzero"].set_visible(False) ax.set_xlim(min_time, max_time) ax.set_ylim(0, 4) ax.set_xlabel("Time") ax.set_ylabel("HRV") t_hrv = [] hrv = [] for val in self.readings: if "hrv" in val.keys(): t_hrv.append(val["time"]) hrv.append(val["hrv"]) else: ax.plot(val["time"], 2.0, 'r.') for peak in self.peaks: ax.plot(peak["time"], peak["hrv"], 'g.', markersize=10) ax.plot(t_hrv, hrv, 'b-') plt.savefig('pulse_graph')
# Espace x,y # Espace Snn,Snt ax2 = SubplotZero(fig, 111) fig.add_subplot(ax2) # for direction in ["xzero", "yzero"]: ax2.axis[direction].set_axisline_style("-|>") ax2.axis[direction].set_visible(True) # for direction in ["left", "right", "bottom", "top"]: ax2.axis[direction].set_visible(False) ax2.set_aspect('equal') ax2.set_xlim(Sig_min, Sig_max) ax2.set_ylim(-(Sig_max-Sig_min)/2, (Sig_max-Sig_min)/2) ax2.text(0., 1.05, '$\sigma_{nt}$',size=20, transform=BlendedGenericTransform(ax2.transData, ax2.transAxes)) ax2.text(1.05, -0.15, '$\sigma_{nn}$',size=20, transform=BlendedGenericTransform(ax2.transAxes, ax2.transData)) ax2.grid() mohr_circle, = ax2.plot([], [], '.r',label='Etat de contrainte', markersize=2) ax2.legend() # ######################## def Snn_Snt_decomposition (Sigma, n) : # Check that norm of n is one n=n/np.linalg.norm(n)
fig = plt.figure(1) Sig_max = 500.0 # Espace x,y ax1 = SubplotZero(fig, 121) fig.add_subplot(ax1) # for direction in ["xzero", "yzero"]: ax1.axis[direction].set_axisline_style("-|>") ax1.axis[direction].set_visible(True) # for direction in ["left", "right", "bottom", "top"]: ax1.axis[direction].set_visible(False) ax1.set_aspect('equal') ax1.set_xlim(-Sig_max, Sig_max) ax1.set_ylim(-Sig_max, Sig_max) ax1.text(0., 1.05, 'y', size=20, transform=BlendedGenericTransform(ax1.transData, ax1.transAxes)) ax1.text(1.05, -0.15, 'x', size=20, transform=BlendedGenericTransform(ax1.transAxes, ax1.transData)) vec_phi_xy = ax1.quiver(0, 0, 0,
leg_list = [ r"$\mathrm{erf}\left(\frac{\sqrt{\pi}}{2}x \right)$", r"$\tanh(x)$", r"$\frac{2}{\pi}\mathrm{gd}\left( \frac{\pi}{2}x \right)$", r"$x\left(1+x^2\right)^{-\frac{1}{2}}$", r"$\frac{2}{\pi}\mathrm{arctan}\left( \frac{\pi}{2}x \right)$", r"$x\left(1+|x|\right)^{-1}$" ] for i in range(1, 7): s = "ax.plot(x,y%s(x),color=colors[i-1])" % (str(i)) eval(s) ax.legend(leg_list, loc="best", ncol=2, fancybox=True) # title="Legend", fontsize=12 # ax.grid(True, which='both') ax.set_aspect('equal') ax.set_xlim([-3.1, 3.1]) ax.set_ylim([-1.1, 1.1]) ax.annotate('1', xy=(0.08, 1 - 0.02)) ax.annotate('0', xy=(0.08, -0.2)) ax.annotate('-1', xy=(0.08, -1 - 0.03)) for i in [-3, -2, -1, 1, 2, 3]: ax.annotate('%s' % str(i), xy=(i - 0.03, -0.2)) maybe = raw_input( "\nUpdate figure directly in master thesis?\nEnter 'YES' (anything else = ONLY show to screen) " ) if maybe == "YES": # Only save to disc if need to be updated filenameWithPath = "/Users/haakonvt/Dropbox/uio/master/latex-master/Illustrations/six_sigmoids.pdf" plt.savefig(filenameWithPath, bbox_inches='tight') #, pad_inches=0.2)
-4, r'$x=y$', color='m') ax.arrow(-5.5, -4.5, 9, 9, color='grey', ls='dashed', lw=.5), ax.text(-6, -3, r'$x=y-1$', color='grey') ax.arrow(-2, -1, 5, 5, color='g', head_width=.2, head_length=.2), ax.text(2.9, 4.2, r'$y$', color='g') ax.arrow(-4.5, 4.5, 9, -9, color='c', ls='dashed', lw=.5), ax.text(-4, 4, r'$x=-y$', color='c') ax.arrow(-2.5, 4.5, 9, -9, color='b', ls='dashed', lw=.5), ax.text(-2, 4, r'$x=y+2$', color='b') ax.arrow(-1, 3, 4, -4, color='g', head_width=.2, head_length=.2), ax.text(2.5, -1, r'$x$', color='g') ax.plot([0, 1, 2], [0, 1, 2], 'ko') ax.text(.1, .1, r'A'), ax.text(1.1, 1, r'M'), ax.text(1.9, 2.1, r'B') #ax.text(10,.1,"x") #ax.text(.1,5,"y") xticks(arange(-6, 11, 1)) yticks(arange(-5, 6, 1)) ax.set_ylim(-5, 5) ax.set_xlim(-6, 10) show() fig.savefig("Test.svg",bbox_inches="tight",\ pad_inches=.15)
from mpl_toolkits.axes_grid.axislines import SubplotZero from matplotlib import colors roll = 15 pitch = 5 orig = [0, 0] X, Y = (0, 0) # origin U = roll V = pitch fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) qv = ax.quiver(X, Y, U, V, color="y", angles="xy", scale_units="xy", scale=1) ax.set_xlim([-45, 45]) ax.set_ylim([-45, 45]) # show cartisian axis for direction in ["xzero", "yzero"]: ax.axis[direction].set_visible(True) # turn off side axis # for direction in ["left", "right", "bottom", "top"]: # ax.axis[direction].set_visible(False) plt.draw() plt.show()
colors = ('r', 'g', 'b') qv = ax.quiver(X, Y, U, V, color=colors, angles='xy', scale_units='xy', scale=1) labels = ('heading: {} deg'.format(hdeg), 'Orientation, drift: {} deg'.format(drift), '{} g at {} deg'.format(aforce, adeg)) pos = ('N', 'E', 'S') for x, y, l, c, p in zip(U, V, labels, colors, pos): plt.quiverkey(qv, x, y, 0, l, color=c, coordinates='data', labelpos=p) ax.set_xlim([-2, 2]) ax.set_ylim([-2, 2]) # show cartisian axis # for direction in ["xzero", "yzero"]: # ax.axis[direction].set_visible(True) # turn off side axis for direction in ["left", "right", "bottom", "top"]: ax.axis[direction].set_visible(False) plt.draw() plt.show()
colors=initialize_graphics() fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) #fig, ax = plt.subplots() fig.set_size_inches(cm2inch([10,5])) ax.plot(full_range, potential, lw=2, color=colors[2]) ax.plot(until_x1, wave_until_x1, lw=2, color=colors[0]) ax.plot(from_x2, wave_from_x2, lw=2, color=colors[0]) ax.annotate('$U(x)$', xy=(x2, V0), xytext=(x2+0.3, V0-0.2)) ax.set_frame_on(False) #ax.axes.get_yaxis().set_visible(False) ax.axes.get_xaxis().set_ticks([x1, x2, 5*np.pi+0.5]) ax.axes.get_xaxis().set_ticklabels(['$x_1$','$x_2$', '$x$']) ax.axis["xzero"].set_axisline_style("-|>") ax.axis["xzero"].set_visible(True) ax.axis["yzero"].set_visible(False) for direction in ["left", "right", "bottom", "top"]: ax.axis[direction].set_visible(False) ax.set_xlim([-0.5, 5*np.pi+0.5]) plt.savefig('./quantum_tunneling.pdf')
class graph(): def __init__(self): self.fig = plt.figure(1) self.ax = SubplotZero(self.fig,111) self.fig.add_subplot(self.ax) for direction in ["xzero","yzero"]: self.ax.axis[direction].set_axisline_style("-|>") self.ax.axis[direction].set_visible(True) for direction in ["left","right","bottom","top"]: self.ax.axis[direction].set_visible(False) def make_graph(self, f): I = f.behaviour("largest interval") ps = float(I.args[0]) pe = float(I.args[1]) t = np.arange(ps, pe, 0.01) self.ax.plot(t, f.eval_np(t)) def make_graphs(self, *functions,Interval=None): if(Interval == None): f = functions[0] I = f.behaviour("largest interval") l,r = float(I.args[0]), float(I.args[1]) for f in functions: I = f.behaviour("largest interval") l,r = min(l,float(I.args[0])), max(r,float(I.args[1])) else: l,r = float(Interval.args[0]), float(Interval.args[1]) self.Interval = sp.Interval(l,r) t = np.arange(l,r,.01) for f in functions: self.ax.plot(t,f.eval_np(t)) def make_secent(self,f,x1,x2): I = f.behaviour("largest interval") ps = float(I.args[0]) pe = float(I.args[1]) t = np.arange(ps, pe, 0.01) sec = f.secent_line(x1,x2) self.ax.plot(t, sec.eval_np(t)) self.plot_point(x1, sec.eval_np(x1)) self.plot_point(x2,sec.eval_np(x2)) def make_tangent(self,f,x): I = f.behaviour("largest interval") ps = float(I.args[0]) pe = float(I.args[1]) t = np.arange(ps, pe, 0.01) tan = f.tangent_line(x) self.ax.plot(t, tan.eval_np(t)) self.plot_point(x, tan.eval_np(x)) def plot_point(self, x, y): self.ax.plot(np.array([x]), np.array([y]), 'ro') def zoom_y(self, f, I): self.zoom_x(I) self.zoom_y(f.range(I)) def zoom_x(self,I): ps = float(I.args[0]) pe = float(I.args[1]) self.ax.set_xlim(ps,pe) def zoom_y(self,I): ps = float(I.args[0]) pe = float(I.args[1]) self.ax.set_ylim(ps,pe) def show(self): return self.fig
ax.text(0, 1.05, 'y', transform=BlendedGenericTransform(ax.transData, ax.transAxes), ha='center') ax.text(1.05, 0, 'x', transform=BlendedGenericTransform(ax.transAxes, ax.transData), va='center') # for direction in ["xzero", "yzero"]: ax.axis[direction].set_axisline_style("-|>") ax.axis[direction].set_visible(True) ax.set_ylim([-10, 10]) ax.set_xlim([-5, 5]) for direction in ["left", "right", "bottom", "top"]: ax.axis[direction].set_visible(False) for label in ax.get_ymajorticklabels(): label.set_rotation(123) for points in [(-10, -2.101, "red"), (-2, 0, "green"), (0.001, 10, "blue")]: x = np.linspace(points[0], points[1], 100) y = 2 / (x**2 + 2 * x) ax.plot(x, y, color="green") x = np.linspace(-10, 10, 100) ax.plot(x, -(2 * (x / x)), "k--")
print h,x,g soa = np.array([h,x,g]) # vectors print soa X,Y,U,V = zip(*soa) # convert to turples of U and V components fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) colors = ('r','g','b') qv = ax.quiver(X,Y,U,V,color=colors,angles='xy',scale_units='xy',scale=1) labels = ('heading: {} deg'.format(hdeg), 'Orientation, drift: {} deg'.format(drift), '{} g at {} deg'.format(aforce,adeg)) pos = ('N','E','S') for x,y,l,c,p in zip(U,V,labels,colors,pos): plt.quiverkey(qv,x,y,0,l,color=c,coordinates='data',labelpos=p) ax.set_xlim([-2,2]) ax.set_ylim([-2,2]) # show cartisian axis # for direction in ["xzero", "yzero"]: # ax.axis[direction].set_visible(True) # turn off side axis for direction in ["left", "right", "bottom", "top"]: ax.axis[direction].set_visible(False) plt.draw() plt.show()
] colors = initialize_graphics() fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) #fig, ax = plt.subplots() fig.set_size_inches(cm2inch([10, 5])) ax.plot(full_range, potential, lw=2, color=colors[2]) ax.plot(until_x1, wave_until_x1, lw=2, color=colors[0]) ax.plot(from_x2, wave_from_x2, lw=2, color=colors[0]) ax.annotate('$U(x)$', xy=(x2, V0), xytext=(x2 + 0.3, V0 - 0.2)) ax.set_frame_on(False) #ax.axes.get_yaxis().set_visible(False) ax.axes.get_xaxis().set_ticks([x1, x2, 5 * np.pi + 0.5]) ax.axes.get_xaxis().set_ticklabels(['$x_1$', '$x_2$', '$x$']) ax.axis["xzero"].set_axisline_style("-|>") ax.axis["xzero"].set_visible(True) ax.axis["yzero"].set_visible(False) for direction in ["left", "right", "bottom", "top"]: ax.axis[direction].set_visible(False) ax.set_xlim([-0.5, 5 * np.pi + 0.5]) plt.savefig('./quantum_tunneling.pdf')
def main(): f = open("game_output.txt", "r") l = json.load(f) min_time = 0 for val in l: if min_time == 0: min_time = val["time"] if val["time"] < min_time: min_time = val["time"] max_time = 0 for val in l: if max_time == 0: max_time = val["time"] if val["time"] > max_time: max_time = val["time"] print "%s %s" % (min_time, max_time) fig = plt.figure(1) fig.subplots_adjust(right=0.85) ax = SubplotZero(fig, 1, 1, 1) fig.add_subplot(ax) # make right and top axis invisible ax.axis["right"].set_visible(False) ax.axis["top"].set_visible(False) # make xzero axis (horizontal axis line through y=0) visible. ax.axis["xzero"].set_visible(False) #ax.axis["xzero"].label.set_text("Axis Zero") ax.set_xlim(min_time, max_time) ax.set_ylim(0, 4) ax.set_xlabel("Time") ax.set_ylabel("HRV") # make new (right-side) yaxis, but wth some offset # offset = (20, 0) # new_axisline = ax.get_grid_helper().new_fixed_axis # ax.axis["right2"] = new_axisline(loc="right", # offset=offset, # axes=ax) # ax.axis["right2"].label.set_text("Label Y2") #ax.plot([-2,3,2]) t_hrv = [] hrv = [] for val in l: if "hrv" in val.keys(): t_hrv.append(val["time"]) hrv.append(val["hrv"]) #ax.plot(val["time"], val["hrv"], 'b,') elif "key" in val.keys(): ax.plot(val["time"], 2.0, 'r,') ax.plot(t_hrv, hrv, 'b-') hrv_dict = [] for el in l: try: hrv_dict.append((el["time"], el["hrv"])) except KeyError: pass peak_dict = [] current_peak = 0 hrv_window = deque() hrv_limit = 20 hrv_total = [] stop_counter = 0 hrv_itr = hrv_dict.__iter__() b = hrv_itr.next() while 1: a = [b[0], b[1], 0] hrv_window.append(a) hrv_total.append(a) if len(hrv_window) > hrv_limit: hrv_window.popleft() max_hrv = 0 max_time = 0 for h in hrv_window: if h[1] > max_hrv: max_time = h[0] max_hrv = h[1] for h in hrv_window: if h[0] == max_time: h[2] = h[2] + 1 break try: c = hrv_itr.next() b = c except StopIteration: stop_counter = stop_counter + 1 if stop_counter == hrv_limit: break pulse = 0 for (time, hrv, score) in hrv_total: if score > 17: pulse = pulse + 1 ax.plot(time, hrv, 'g,') print "Pulse: %s" % (pulse) plt.draw() plt.show()
from mpl_toolkits.axes_grid.axislines import SubplotZero from matplotlib import colors roll = 15 pitch = 5 orig = [0, 0] X, Y = (0, 0) # origin U = roll V = pitch fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) qv = ax.quiver(X, Y, U, V, color='y', angles='xy', scale_units='xy', scale=1) ax.set_xlim([-45, 45]) ax.set_ylim([-45, 45]) # show cartisian axis for direction in ["xzero", "yzero"]: ax.axis[direction].set_visible(True) # turn off side axis # for direction in ["left", "right", "bottom", "top"]: # ax.axis[direction].set_visible(False) plt.draw() plt.show()