Python 小目标11

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,126评论 0 10
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 13,140评论 0 13
  • Data Visualization with D3 D3: SVG中的jQurey 1. Add Documen...
    王策北阅读 4,117评论 0 2
  • 逐渐爱上它,爱上陪伴它,一笔一画,感受自心安静或者急躁,快乐或者悲伤的那份感觉…… 睡觉前来一份...
    观心客阅读 3,030评论 1 0
  • 本文主要分两部分,第一部分(前三章)介绍了当前国内外在海量数据处理方面的成果及相关技术,第二部分(后三章)是基于h...
    via_lz阅读 3,437评论 0 1