def plot_2vfunc_domain(plot_lst): inf_lst = extract_information2v(plot_lst) fig = plt.figure(figsize=(10, 10)) ax = SubplotZero(fig, 111) fig.add_subplot(ax) # fun_name = inf_lst[1] for i in inf_lst: bound_color = i[0] # print i xy_x = i[1][0][0][0] xy_y = i[1][0][0][1] lgt = i[1][0][1] hgt = i[1][0][2] rect = plt.Rectangle((xy_x, xy_y), lgt, hgt, fill=True, facecolor=bound_color, edgecolor='red', linewidth=0) ax.add_patch(rect) # plt.ylim((-0.25, 0.25)) plt.xlim((-2150, 2150)) plt.ylim((-2150, 2150)) plt.show()
def plot_1func_domain(plot_lst): inf_lst = extract_information(plot_lst) fig = plt.figure(figsize=(25, 2)) ax = SubplotZero(fig, 111) fig.add_subplot(ax) for i in inf_lst: bound_color = i[0] print i xy_x = i[1][0][0][0] xy_y = i[1][0][0][1] lgt = i[1][0][1] rect = plt.Rectangle((xy_x, xy_y), lgt, 0.5, fill=True, facecolor=bound_color, edgecolor=bound_color, linewidth=0) ax.add_patch(rect) plt.ylim((-0.25, 0.25)) plt.xlim((-2150, 2150)) plt.yticks([]) # plt.savefig("graph2/" + fun_name + ".pdf", format="pdf") plt.savefig("papergraph/" + "erfbdvals.eps", format="eps") # plt.close() plt.show()
def myplot(P): plt.xkcd() fig = plt.figure() ax = SubplotZero(fig, 111) fig.add_subplot(ax) plt.axhline(y=0, color='#636363') plt.axvline(x=0, color='#636363') ax.set(xlabel='$x$', ylabel='$f(x)$', title='Newton Method') x = arange(P - 2 * abs(P), P + 2 * abs(P), 0.01) y = [f(i) for i in x] ax.plot(x, y, label='$f(x)$') ax.plot([P], [0], 'ro-', label='root') ax.legend() plt.show()
def test_SubplotZero(): fig = plt.figure() ax = SubplotZero(fig, 1, 1, 1) fig.add_subplot(ax) ax.axis["xzero"].set_visible(True) ax.axis["xzero"].label.set_text("Axis Zero") for n in ["top", "right"]: ax.axis[n].set_visible(False) xx = np.arange(0, 2 * np.pi, 0.01) ax.plot(xx, np.sin(xx)) ax.set_ylabel("Test")
def dyhotomia(request): if 1: postSave = float(request.POST['formA']) postS(postSave) l = 0.0 lmax = 0.6 E = 1e-4 y = 0.0 f = plt.figure(1) ax = SubplotZero(f, 111) f.add_subplot(ax) x = l xmax = lmax Ua = 0.0 U = 0.0 while (np.abs(l - lmax) >= E): Ua = func(l) U = func((l + lmax) / 2) if Ua * U > 0: l = (l + lmax) / 2 else: lmax = (l + lmax) / 2 y = (l + lmax) / 2 for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) x = np.linspace(x, xmax, 100) ax.plot(y, funcg(y), 'o', x, funcg(x)) print(y) print(Ua) print(U) print(I) print(a) buf = io.BytesIO() plt.grid(True) plt.savefig(buf, format='svg') plt.close(f) response = HttpResponse(buf.getvalue(), content_type='image/svg+xml') return response
def rectangle(a, b, n): if 1: f = plt.figure(1) ax = SubplotZero(f, 111) f.add_subplot(ax) dx = (b - a) / float(n) total = 0 for k in range(0, n): total = total + func((a + (k * dx))) return dx * total
def dyhotomia(request): if 1: a = float(request.POST['a']) b = float(request.POST['b']) e = float(request.POST['e']) y=0.0 i=a f = plt.figure(1) ax = SubplotZero(f, 111) f.add_subplot(ax) mas = np.arange(a, b, e) x = a xmax = b while(np.abs(a - b)>=e): Ua = func(a) U = func((a+b)/2) if Ua*U > 0: a = (a+b)/2 else: b = (a+b)/2 y = (a+b)/2 for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) x = np.linspace(x, xmax, 100) ax.plot(y, func(y), 'o', x, func(x)) print(y) buf = io.BytesIO() plt.grid(True) plt.savefig(buf, format='svg') plt.close(f) response = HttpResponse(buf.getvalue(), content_type='image/svg+xml') return response
def mplimage(request): if 1: postSave = float(request.POST['formA']) postS(postSave) l = 0 lmax = 0.6 E = 1e-4 y = 0.0 iu = 0 f = plt.figure(1) ax = SubplotZero(f, 111) f.add_subplot(ax) mas = np.arange(l, lmax, E) for i in mas: y1 = func(i) y2 = func(i + E) if y1 * y2 < 0: iu = (i + i + E) / 2 break for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) x = np.linspace(l, lmax, 100) ax.plot(iu, funcg(iu), 'o', x, funcg(x)) print(iu) print(y1) print(y2) print(I) buf = io.BytesIO() plt.grid(True) plt.savefig(buf, format='svg') plt.close(f) response = HttpResponse(buf.getvalue(), content_type='image/svg+xml') return response
def newton(request): if 1: postSave = float(request.POST['formA']) postS(postSave) l = 0.0 lmax = 0.6 E = 1e-4 f = plt.figure(1) ax = SubplotZero(f, 111) f.add_subplot(ax) x = l xmax = lmax if (func(l) * d2Func(l) > 0): x0 = l else: x0 = lmax xn = x0 - func(x0) / dFunc(x0) while (np.abs(x0 - xn) > E): x0 = xn xn = x0 - func(x0) / dFunc(x0) for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) x = np.linspace(x, xmax, 100) ax.plot(xn, funcg(xn), 'o', x, funcg(x)) print("newton", xn) buf = io.BytesIO() plt.grid(True) plt.savefig(buf, format='svg') plt.close(f) response = HttpResponse(buf.getvalue(), content_type='image/svg+xml') return response
def newton(request): if 1: a = float(request.POST['a']) b = float(request.POST['b']) e = float(request.POST['e']) y=0.0 i=a f = plt.figure(1) ax = SubplotZero(f, 111) f.add_subplot(ax) x = a xmax = b if(func(a)*d2Func(a) > 0): x0 = a else: x0 = b xn = x0 - func(x0) / dFunc(x0) while(np.abs(x0 - xn) > e): x0 = xn xn = x0 - func(x0) / dFunc(x0) for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) x = np.linspace(x, xmax, 100) ax.plot(xn, func(xn), 'o', x, func(x)) print(xn) buf = io.BytesIO() plt.grid(True) plt.savefig(buf, format='svg') plt.close(f) response = HttpResponse(buf.getvalue(), content_type='image/svg+xml') return response # Create your views here.
def nice(): x, y, z = symbols('x y z') init_printing(use_unicode=True) rango_1 = float(input("rango 1: ")) rango_2 = float(input("rango 2: ")) resolution = int(input("resolucion: ")) print("formula") function = input() results=[] value_x = [] value_y = [] cosa = ((rango_2 - rango_1) / resolution) for x_n in np.arange(rango_1,rango_2, cosa): cosa2 = (rango_1 + (((rango_2 - rango_1) / 2 * resolution) * (2*x_n - 1))) value_y.append(cosa * sympify(function).evalf(subs={x: cosa2})) #value_y.append(sympify("x**2").evalf(subs={x: x_n})) for y_n in np.arange(rango_1,rango_2, cosa): value_x.append(y_n) print(value_x,value_y) fig = plt.figure() 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.y(value_x, value_y) plt.savefig('foo.svg')
def plot_func(section, func): fig = plt.figure(1, (10, 6)) ax = SubplotZero(fig, 1, 1, 1) fig.add_subplot(ax) x0 = linspace(section[0], section[1], 1000) y0 = [] for i in range(1000): y0.append(func(x0[i])) ax.axis["xzero"].set_visible(True) ax.axis["xzero"].label.set_color('green') ax.axis["yzero"].set_visible(True) ax.axis["yzero"].label.set_color('green') plt.plot(x0, y0, 'r-', color='b') plt.show()
def mplimage(request): if 1: a = float(request.POST['a']) b = float(request.POST['b']) e = float(request.POST['e']) y=0.0 i=a f = plt.figure(1) ax = SubplotZero(f, 111) f.add_subplot(ax) mas = np.arange(a, b, e) for i in mas: y1=func(i) y2=func(i+e) if y1*y2<0: y = (i + i+e)/2 for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) x = np.linspace(a, b, 100) ax.plot(y, func(y), 'o', x, func(x)) print(y) buf = io.BytesIO() plt.grid(True) plt.savefig(buf, format='svg') plt.close(f) response = HttpResponse(buf.getvalue(), content_type='image/svg+xml') return response
def creator(self, a, b, c, minn, maxx): '''A method that creates the graph and adjust the axis.''' y = list() x = np.linspace(minn, maxx) for i in x: y.append((a * i * i) + (b * i) + c) fig = plt.figure() ax = SubplotZero(fig, 111) fig.add_subplot(ax) ax.axis['xzero'].set_visible(True) ax.axis['yzero'].set_visible(True) for i in ["left", "right", "bottom", "top"]: ax.axis[i].set_visible(False) plt.plot(x, y) plt.show()
def plot_func_str(section, expression): fig = plt.figure(1, (10, 6)) ax = SubplotZero(fig, 1, 1, 1) fig.add_subplot(ax) x0 = linspace(section[0], section[1], 1000) x = symbols('x') y0 = [] for i in range(1000): y0.append(sympify(expression).evalf(subs={x: x0[i]})) ax.axis["xzero"].set_visible(True) ax.axis["xzero"].label.set_color('green') ax.axis["yzero"].set_visible(True) ax.axis["yzero"].label.set_color('green') plt.plot(x0, y0, 'r-', color='b') plt.show()
def calulitos(a_o, b_o, n_o, function): s_x = symbols("x") print("funcion a usar ---> ", function) np.seterr(divide='ignore', invalid='ignore') f = lambda x: lambdify(s_x, sympify(function), 'numpy')(x) a = a_o b = b_o N = n_o n = n_o # Use n*N+1 points to plot the function smoothly xe = np.linspace(a, b, N + 1) y = f(xe) X = np.linspace(a, b, n * N + 1) Y = f(X) fig = plt.figure() 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) plt.subplot(1, 3, 2) plt.plot(X, Y, color="red") x_mid = (xe[:-1] + xe[1:]) / 2 # Midpoints y_mid = f(x_mid) plt.plot(x_mid, y_mid, color="red") plt.bar(x_mid, y_mid, width=(b - a) / N, edgecolor='b') plt.title('Midpoint Riemann Sum, N = {}'.format(N)) plt.savefig('foo.png', dpi=500) vistas.resultado("foo.png")
def test_SubplotZero(): # Remove this line when this test image is regenerated. plt.rcParams['text.kerning_factor'] = 6 fig = plt.figure() ax = SubplotZero(fig, 1, 1, 1) fig.add_subplot(ax) ax.axis["xzero"].set_visible(True) ax.axis["xzero"].label.set_text("Axis Zero") for n in ["top", "right"]: ax.axis[n].set_visible(False) xx = np.arange(0, 2 * np.pi, 0.01) ax.plot(xx, np.sin(xx)) ax.set_ylabel("Test")
def main(): # データ x = np.arange(-5, 5, 1) y = [1.0] * 1000 # プロット fig = plt.figure() ax = SubplotZero(fig, 111) fig.add_subplot(ax) plot_arrow(ax, x, y, 1) # 表示設定 margin = 0.5 set_display(fig, ax) ax.set_xlim(x[0] - margin, x[-1] + margin) ax.set_ylim(-0.2, 1.5) # ファイル保存 fig.savefig("arrow.png") # 表示 plt.show()
alphabet[4], horizontalalignment='center', verticalalignment='center', fontsize=16, fontweight='demibold', transform=ax.transAxes) plotting.remove_axis_junk(ax) t = np.arange(p_net.shape[1]) * PSET.dt * PSET.decimate_q inds = (t >= T[0]) & (t <= T[1]) ax.plot(t[inds], p_net[i, inds], 'k', lw=1) ax.set_ylabel(ylabel) ax.set_xticklabels([]) # panel F. Illustration of 4-sphere volume conductor model geometry ax = SubplotZero(fig, gs[2, 1]) fig.add_subplot(ax) ax.set_title('four-sphere volume conductor model') for direction in ["xzero"]: ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: ax.axis[direction].set_visible(False) theta = np.linspace(0, np.pi, 31) # draw some circles: for i, r, label in zip(range(4), PSET.foursphereParams['radii'], ['brain', 'CSF', 'skull', 'scalp']): ax.plot(np.cos(theta) * r,
def ellipse(): # theta ranges from 0 to 2pi npts = 360 theta = np.linspace(0, 2*np.pi, npts) e = 0.5 a = 1.0 r = a*(1.0 - e**3)/(1.0 + e*np.cos(theta)) x = r*np.cos(theta) y = r*np.sin(theta) # plotting for n in range(npts): fig = plt.figure(1) fig.clear() ax = SubplotZero(fig, 111) fig.add_subplot(ax) ax.set_aspect("equal", "datalim") ax = plt.gca() ax.set_aspect("equal", "datalim") # draw the ellipse ax.plot(x, y, color="k", linewidth=2) # draw our current point ax.scatter([x[n]], [y[n]], color="k", s=75) # second foci ax.scatter([-2.0*a*e], [0], color="C0", marker="x", s=200) # primary foci ax.scatter([0], [0], color="C1", marker="x", s=200) # draw lines connecting the foci to the current point ax.plot([0, x[n]], [0, y[n]], color="C1", zorder=100, linewidth=2) ax.plot([-2.0*a*e, x[n]], [0, y[n]], color="C0", zorder=100, linewidth=2) ax.set_xlim(-2.5, 1.5) ax.set_ylim(-2., 2.) len1 = np.sqrt((x[n] - 0)**2 + (y[n] - 0)**2) len2 = np.sqrt((x[n] - (-2.0*a*e))**2 + (y[n] - 0)**2) ax.set_title("Ellipse, eccenticity = {:5.3f}".format(e)) ax.text(-1.5, -1.25, "r length: {:5.3f}".format(len1), color="C1") ax.text(-1.5, -1.5, "r' length: {:5.3f}".format(len2), color="C0") ax.text(-1.5, -1.75, "r + r' = {:5.3f}".format(len1 + len2)) for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) fig.set_size_inches(7.2, 7.2) fig.set_size_inches(7.2,7.2) plt.savefig("ellipsedraw_{:03d}.png".format(n))
ax0.axis('off') ax0.set_title('extracellular potential') ax1 = fig.add_subplot(gs[:6, 1], aspect='equal') # dipole moment ill. ax1.axis('off') ax1.set_title('extracellular potential') ax2 = fig.add_subplot(gs[:6, 2], aspect='equal') # dipole moment ill. ax2.axis('off') ax2.set_title('magnetic field') # ax3 = fig.add_subplot(gs[0, 3], aspect='equal') # spherical shell model ill. # ax3.set_title('4-sphere volume conductor') # ax4 = fig.add_subplot(gs[1, 3], # aspect='equal' # ) # MEG/EEG forward model ill. # ax4.set_title('EEG and MEG signal detection') ax3 = SubplotZero(fig, gs[7:, 0]) fig.add_subplot(ax3) ax3.set_title('4-sphere volume conductor', verticalalignment='bottom') ax4 = fig.add_subplot(gs[7:, 1]) # EEG ax4.set_title('scalp electric potential $\phi_\mathbf{p}(\mathbf{r})$') ax5 = fig.add_subplot(gs[7:, 2], sharey=ax4) # MEG # ax5.set_title('scalp magnetic field') #morphology - line sources for panels A and B zips = [] xz = cell.get_idx_polygons() for x, z in xz: zips.append(list(zip(x, z))) for ax in [ax0]: polycol = PolyCollection(zips, linewidths=(0.5),
""" ================ Axis line styles ================ This example shows some configurations for axis style. """ from mpl_toolkits.axisartist.axislines import SubplotZero import matplotlib.pyplot as plt import numpy as np if 1: fig = plt.figure() ax = SubplotZero(fig, 111) fig.add_subplot(ax) for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) x = np.linspace(-0.5, 1., 100) ax.plot(x, np.sin(x * np.pi))
""" ================ Axis line styles ================ This example shows some configurations for axis style. """ from mpl_toolkits.axisartist.axislines import SubplotZero import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = SubplotZero(fig, 111) fig.add_subplot(ax) for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) x = np.linspace(-0.5, 1., 100) ax.plot(x, np.sin(x*np.pi))
# -*- coding: utf-8 -*- """ Created on Mon May 11 20:25:31 2020 @author: edels """ import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.axisartist.axislines import SubplotZero t = np.linspace(0, 2 * np.pi, 15) V = np.sin(t) fig = plt.figure(figsize=(1, 1)) ax = SubplotZero(fig, 1, 1, 1) fig.add_subplot(ax) ax.axis["xzero"].set_visible(True) for n in ["bottom", "top", "right"]: ax.axis[n].set_visible(False) # Step graph ax.step(t, V, color="black", linewidth=2) # Stem graph #(markerline, stemlines, baselines) = ax.stem(t, V, linefmt = "black", basefmt = " ", use_line_collection = True) #plt.setp(markerline, color = "black", markersize = 3) # Allow to edit stem markerline color # Continuous line graph #ax.plot(t, V, color = "black", linewidth = 2)
def ellipse(): # theta ranges from 0 to 2pi npts = 360 theta = np.linspace(0, 2 * np.pi, npts) # well go through a range of eccentricities (forwards and backwards) n_ecc = 200 e_tmp = np.linspace(0, 0.95, n_ecc) ecc = np.zeros(2 * n_ecc) ecc[0:n_ecc] = e_tmp[:] ecc[n_ecc:] = e_tmp[::-1] a = 1.0 for n, e in enumerate(ecc): r = a * (1.0 - e**2) / (1.0 + e * np.cos(theta)) x = r * np.cos(theta) y = r * np.sin(theta) # plotting fig = plt.figure(1) fig.clear() ax = SubplotZero(fig, 111) fig.add_subplot(ax) ax.set_aspect("equal", "datalim") ax.plot(x, y, color="k", linewidth=2) # second foci ax.scatter([-2.0 * a * e], [0], color="C0", marker="x", s=100) # primary foci ax.scatter([0], [0], color="C1", marker="x", s=100) ax.set_xlim(-2.5, 1.5) ax.set_ylim(-2., 2.) ax.text(-2.0, -1.5, "a = %5.3f, e = %6.4f" % (a, e)) for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) fig.set_size_inches(7.2, 7.2) plt.savefig("ellipse_{:03d}.png".format(n))
f[i] = f[i].replace(',', '.').strip("\n") f[i] = f[i].split('\t') accumulator.append((np.radians(float(f[i][0])), float(f[i][1]))) a = [] b = [] theta = [] rho = [] N = len(accumulator) for i in range(0, N): theta.append(accumulator[i][0]) rho.append(accumulator[i][1]) fig = plt.figure(1) ax = SubplotZero(fig, 111) #ax.set_facecolor((0, 0, 0)) fig.add_subplot(ax) #ax.axhline(color="yellow") #ax.axvline(color="yellow") #ax.set_xticks([1]) #ax.set_yticks([1]) #ax.set_xticklabels(['x']) #ax.set_yticklabels(['y']) #ax.axis("equal") 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)
#%% import matplotlib.pyplot as plt from mpl_toolkits.axisartist.axislines import SubplotZero import numpy as np degrees = np.load('data/degrees_MNIST.npy').transpose() x = np.arange(6000) for i in range(4): plt.plot(x, degrees[i]) plt.title('Layer %i ' % (i + 1)) plt.xlabel('# of update steps') plt.ylabel('Degrees (°)') plt.ylim(40, 100) plt.savefig('img/MNIST_DFA_l%i.png' % (i + 1)) plt.close() #%% showrange = 6000 fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) x = np.arange(showrange) lines = [] for i in range(4): l, = ax.plot(x, degrees[i][:showrange]) lines.append(l) ax.legend(lines, ['layer %i' % i for i in range(4)]) ax.set_xlabel('# of update steps') ax.set_ylabel('Degrees (°)') plt.savefig('img/MNIST_DFA_%isteps.png' % showrange)
def ellipse(): # theta ranges from 0 to 2pi npts = 360 theta = np.linspace(0, 2 * np.pi, npts) e = 0.5 a = 1.0 r = a * (1.0 - e**3) / (1.0 + e * np.cos(theta)) x = r * np.cos(theta) y = r * np.sin(theta) # plotting for n in range(npts): fig = plt.figure(1) fig.clear() ax = SubplotZero(fig, 111) fig.add_subplot(ax) ax.set_aspect("equal", "datalim") ax = plt.gca() ax.set_aspect("equal", "datalim") # draw the ellipse ax.plot(x, y, color="k", linewidth=2) # draw our current point ax.scatter([x[n]], [y[n]], color="k", s=75) # second foci ax.scatter([-2.0 * a * e], [0], color="C0", marker="x", s=200) # primary foci ax.scatter([0], [0], color="C1", marker="x", s=200) # draw lines connecting the foci to the current point ax.plot([0, x[n]], [0, y[n]], color="C1", zorder=100, linewidth=2) ax.plot([-2.0 * a * e, x[n]], [0, y[n]], color="C0", zorder=100, linewidth=2) ax.set_xlim(-2.5, 1.5) ax.set_ylim(-2., 2.) len1 = np.sqrt((x[n] - 0)**2 + (y[n] - 0)**2) len2 = np.sqrt((x[n] - (-2.0 * a * e))**2 + (y[n] - 0)**2) ax.set_title("Ellipse, eccenticity = {:5.3f}".format(e)) ax.text(-1.5, -1.25, "r length: {:5.3f}".format(len1), color="C1") ax.text(-1.5, -1.5, "r' length: {:5.3f}".format(len2), color="C0") ax.text(-1.5, -1.75, "r + r' = {:5.3f}".format(len1 + len2)) for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) fig.set_size_inches(7.2, 7.2) fig.set_size_inches(7.2, 7.2) plt.savefig("ellipsedraw_{:03d}.png".format(n))
""" =============== Simple Axisline =============== """ import matplotlib.pyplot as plt from mpl_toolkits.axisartist.axislines import SubplotZero if 1: 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(True) ax.axis["xzero"].label.set_text("Axis Zero") ax.set_ylim(-2, 4) ax.set_xlabel("Label X") ax.set_ylabel("Label Y") # or #ax.axis["bottom"].label.set_text("Label X") #ax.axis["left"].label.set_text("Label Y")
horizontalalignment='center', verticalalignment='center', fontsize=16, fontweight='demibold', transform=ax.transAxes) plotting.remove_axis_junk(ax) t = np.arange(p_net.shape[1])*PSET.dt*PSET.decimate_q inds = (t >= T[0]) & (t <= T[1]) ax.plot(t[inds], p_net[i, inds], 'k', lw=1) ax.set_ylabel(ylabel) ax.set_xticklabels([]) # panel F. Illustration of 4-sphere volume conductor model geometry ax = SubplotZero(fig, gs[2, 1]) fig.add_subplot(ax) ax.set_title('four-sphere volume conductor model') for direction in ["xzero"]: ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: ax.axis[direction].set_visible(False) theta = np.linspace(0, np.pi, 31) # draw some circles: for i, r, label in zip(range(4), PSET.foursphereParams['radii'], ['brain', 'CSF', 'skull', 'scalp']): ax.plot(np.cos(theta)*r, np.sin(theta)*r, 'C{}'.format(i), label=label + r', $r_%i=%i$ mm' % (i+1, r / 1000), clip_on=False)
def plot_point(self, point): x_limit = 10 y_limit = 5 fig = plt.figure(1, figsize=(8, 4)) ax = SubplotZero(fig, 1, 1, 1) fig.add_subplot(ax) ax.grid(color='#eeeeee', linestyle='-', linewidth=2) ax.set_xticks(np.arange(-1 * x_limit, x_limit, 1)) ax.set_xlim(-1 * x_limit, x_limit) ax.set_yticks(np.arange(-1 * y_limit, y_limit, 1)) ax.set_ylim(-1 * y_limit, y_limit) ax.axis['xzero'].set_axisline_style('-|>') ax.axis['xzero'].set_visible(True) ax.axis["xzero"].label.set_text('$x_1$') ax.axis['yzero'].set_axisline_style('-|>') ax.axis['yzero'].set_visible(True) ax.axis["yzero"].label.set_text('$x_2$') ax.plot(*point, 'ro', label='$x^{*}$') ax.legend()
from mpl_toolkits.axisartist.axislines import SubplotZero import matplotlib.pyplot as plt import numpy as np fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) plt.text(-2, 2, r"y=kx+b", horizontalalignment='center', fontsize=20) x = np.linspace(-2, 2, 100) k = -1 b = 0 y = k * x + b ax.plot(x, y) plt.show()
import matplotlib.pyplot as plt from mpl_toolkits.axisartist.axislines import SubplotZero import numpy as np fig = plt.figure(1, (4,3)) # a subplot with two additiona axis, "xzero" and "yzero". "xzero" is # y=0 line, and "yzero" is x=0 line. ax = SubplotZero(fig, 1, 1, 1) fig.add_subplot(ax) # make xzero axis (horizontal axis line through y=0) visible. ax.axis["xzero"].set_visible(True) ax.axis["xzero"].label.set_text("Axis Zero") # make other axis (bottom, top, right) invisible. for n in ["bottom", "top", "right"]: ax.axis[n].set_visible(False) xx = np.arange(0, 2*np.pi, 0.01) ax.plot(xx, np.sin(xx)) plt.show()
""" =============== Simple Axisline =============== """ import matplotlib.pyplot as plt from mpl_toolkits.axisartist.axislines import SubplotZero 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(True) ax.axis["xzero"].label.set_text("Axis Zero") ax.set_ylim(-2, 4) ax.set_xlabel("Label X") ax.set_ylabel("Label Y") # or #ax.axis["bottom"].label.set_text("Label X") #ax.axis["left"].label.set_text("Label Y") # make new (right-side) yaxis, but wth some offset
Description: matplotlib 绘制 sinx """ import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.axisartist.axislines import SubplotZero if __name__ == '__main__': # 坐标点 x = np.linspace(0, 2 * np.pi, num=256) y = np.sin(x) # 坐标轴 fig = plt.figure(1) ax = SubplotZero(fig, 1, 1, 1) 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) plt.xticks([0, np.pi / 2, np.pi, 3 * np.pi / 2, 2 * np.pi], ['$0$', '$\pi/2$', '$\pi$', r'$3\pi/2$', r'$2\pi$']) # 图像 ax.plot(x, y) # 标题 ax.set_title('y = sin(x)') # 展示
def ellipse(): # theta ranges from 0 to 2pi npts = 360 theta = np.linspace(0, 2*np.pi, npts) # well go through a range of eccentricities (forwards and backwards) n_ecc = 200 e_tmp = np.linspace(0, 0.95, n_ecc) ecc = np.zeros(2*n_ecc) ecc[0:n_ecc] = e_tmp[:] ecc[n_ecc:] = e_tmp[::-1] a = 1.0 for n, e in enumerate(ecc): r = a*(1.0 - e**2)/(1.0 + e*np.cos(theta)) x = r*np.cos(theta) y = r*np.sin(theta) # plotting fig = plt.figure(1) fig.clear() ax = SubplotZero(fig, 111) fig.add_subplot(ax) ax.set_aspect("equal", "datalim") ax.plot(x, y, color="k", linewidth=2) # second foci ax.scatter([-2.0*a*e], [0], color="C0", marker="x", s=100) # primary foci ax.scatter([0], [0],color="C1", marker="x", s=100) ax.set_xlim(-2.5, 1.5) ax.set_ylim(-2., 2.) ax.text(-2.0, -1.5, "a = %5.3f, e = %6.4f" % (a, e)) for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) fig.set_size_inches(7.2, 7.2) plt.savefig("ellipse_{:03d}.png".format(n))