大数据Aha数学

Python 小目标11

2019-06-22  本文已影响0人  不连续小姐

Python Day 17: Polar Coordinate in Python

" You are round and short,
.

.

in polar coordinate."

So today we will introduce the most basic calculation in Python for the Polar coordinates.

z= x+ yi (x, y in R, i in C)*

[caption id="attachment_2464" align="alignnone" width="500"] image

Noel_Bauza / Pixabay[/caption]

Output format:

first line τ: distance from z to origin.
second line φ: counterclockwise angle measure from the positive x-axis to the line segment that joins z to the origin.

Code:

import cmath
a=cmath.polar(complex(1.0,2.0))
print(a,sep="\")

Output:
(2.23606797749979, 1.1071487177940904)

Polar Plot

image
import numpy as np
import matplotlib.pyplot as plt

# Fixing random state for reproducibility
np.random.seed(19680801)

# Compute areas and colors
N = 150
r = 2 * np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
area = 200 * r**2
colors = theta

fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)

Happy Practicing!

Reference:

https://www.hackerrank.com/challenges/polar-coordinates/problem

https://matplotlib.org/3.1.0/gallery/pie_and_polar_charts/polar_scatter.html

上一篇下一篇

猜你喜欢

热点阅读