File:Atan2 diagram.svg

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
From Wikipedia, the free encyclopedia

Original file(SVG file, nominally 575 × 449 pixels, file size: 202 KB)

Summary

Description
English: 3D view of
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 - ref) % (2*np.pi) - np.pi + 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.arctan2(y, x)
zc = np.arctan2(*np.meshgrid(yc, xc))
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.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"$\operatorname{atan2}(y, x)$", fontsize=18)
plt.savefig("atan2.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

b144b7c4757e2d84922e158dd77631d744162315

207,114 byte

449 pixel

575 pixel

File history

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

Date/TimeThumbnailDimensionsUserComment
current18:55, 12 May 2020Thumbnail for version as of 18:55, 12 May 2020575 × 449 (202 KB)Geek3also plot tiles along the discontinuity
22:40, 16 February 2016Thumbnail for version as of 22:40, 16 February 2016575 × 449 (230 KB)NicoguaroUser created page with UploadWizard
The following pages on the English Wikipedia use this file (pages on other projects are not listed):

Global file usage

The following other wikis use this file:

Metadata