File:Atan diagram.svg

From testwiki
Jump to navigation Jump to search
    Original file (SVG file, nominally 575 × 449 pixels, file size: 204 KB)

    This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

    Summary

    Description
    English: 3D view of arctan⁡(yx)
    Date
    Source Own work
    Author Nicoguaro
    SVG development
    InfoField
     The SVG code is valid.
     This plot was created with Matplotlib.
    Source code
    InfoField

    Python code

    #!/usr/bin/python2
    
    import numpy as np
    from mpl_toolkits.mplot3d import Axes3D
    from mpl_toolkits.mplot3d.art3d import Poly3DCollection
    from matplotlib import cm
    import matplotlib.pyplot as plt
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    vmin, vmax = -np.pi, np.pi
    plot_args = {'cmap':'YlGnBu_r', 'linewidth': 0.4, 'antialiased': True}
    cmap = cm.get_cmap(plot_args['cmap'])
    
    def modpi(x, ref):
        return (x + np.pi/2 - ref) % (np.pi) - np.pi/2 + ref
    
    xa = np.linspace(-1, 1, 31)
    xc = 0.5 * (xa[:-1] + xa[1:])
    ya = np.linspace(-1, 1, 31)
    yc = 0.5 * (ya[:-1] + ya[1:])
    
    y, x = np.meshgrid(ya, xa)
    z = np.arctan(y / x)
    ym, xm = np.meshgrid(yc, xc)
    zc = np.arctan(ym / xm)
    colors = cmap((zc.flatten() - vmin) / (vmax - vmin))
    
    verts = []
    for ix in range(len(xa)-1):
        for iy in range(len(ya)-1):
            zm = zc[ix, iy]
            polygon = [
                (xa[ix], ya[iy], modpi(z[ix,iy], zm)),
                (xa[ix], ya[iy+1], modpi(z[ix,iy+1], zm)),
                (xa[ix+1], ya[iy+1], modpi(z[ix+1,iy+1], zm)),
                (xa[ix+1], ya[iy], modpi(z[ix+1,iy], zm))]
            
            for i, p in enumerate(polygon):
                if (p[0], p[1]) == (0., 0.):
                    z1 = polygon[(i-1)%len(polygon)][2]
                    z2 = polygon[(i+1)%len(polygon)][2]
                    new_points = [(p[0], p[1], z1), (p[0], p[1], z2)]
                    polygon = polygon[:i] + new_points + polygon[i+1:]
            
            verts.append(polygon)
    
    ax.add_collection3d(Poly3DCollection(verts, facecolors=colors, **plot_args))
    
    #ax.plot_surface(x, y, z, **plot_args)
    ax.view_init(azim=-70, elev=60)
    ax.set_xlim(-1, 1)
    ax.set_ylim(-1, 1)
    ax.set_zlim(vmin, vmax)
    plt.xticks([-1, -0.5, 0, 0.5, 1],
               [r"$-1$", r"$-1/2$", r"$0$", r"$1/2$", r"$1$"])
    plt.yticks([-1, -0.5, 0, 0.5, 1],
               [r"$-1$", r"$-1/2$", r"$0$", r"$1/2$", r"$1$"])
    ax.set_zticks([-np.pi, 0, np.pi])
    ax.set_zticklabels([r"$-\pi$", r"$0$", r"$\pi$"])
    ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 0.0)) 
    ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 0.0)) 
    ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
    ax.set_xlabel(r"$x$", fontsize=18)
    ax.set_ylabel(r"$y$", fontsize=18)
    ax.set_zlabel(r"$\arctan(y/x)$", fontsize=18)
    plt.savefig("atan.svg", bbox_inches="tight", transparent=True)
    plt.show()
    

    Licensing

    I, the copyright holder of this work, hereby publish it under the following license:
    w:en:Creative Commons
    attribution
    This file is licensed under the Creative Commons Attribution 4.0 International license.
    You are free:
    • to share – to copy, distribute and transmit the work
    • to remix – to adapt the work
    Under the following conditions:
    • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

    Captions

    Add a one-line explanation of what this file represents

    Items portrayed in this file

    depicts

    16 February 2016

    image/svg+xml

    5aa2e6e6c775fdbee78436109cb7f18061bc8c99

    209,137 byte

    449 pixel

    575 pixel

    File history

    Click on a date/time to view the file as it appeared at that time.

    Date/TimeThumbnailDimensionsUserComment
    current20:54, 12 May 2020Thumbnail for version as of 20:54, 12 May 2020575 × 449 (204 KB)wikimediacommons>Geek3plot tiles up to the discontinuity

    There are no pages that use this file.