python用matplotlib画球_python 如何用matplotlib画一个漂亮的圆?

01

import numpy as np

import matplotlib.pyplot as plt

# 该行用于设置chart 的样式,可以注掉

plt.style.use("mystyle")

fig = plt.figure(figsize=(8,8))

ax = fig.add_subplot(111)

ax.spines['left'].set_color('none')

ax.spines['bottom'].set_color('none')

ax.spines['right'].set_color('none')

ax.spines['top'].set_color('none')

ax.set_xticks([])

ax.set_yticks([])

# 实现功能

theta = np.arange(0, 2 * np.pi + 0.1,2 * np.pi / 1000)

x = np.cos(theta)

y = np.sin(theta)

v = np.linspace(0, 10, 100)

v.shape = (100, 1)

x = v * x

y = v * y

plt.plot(x, y, color='red')

plt.show()

02

import numpy as np

import matplotlib.pyplot as plt

# 该行用于设置chart 的样式,可以注掉

plt.style.use("mystyle")

fig = plt.figure(figsize=(8,8))

ax = fig.add_subplot(111)

ax.spines['left'].set_color('none')

ax.spines['bottom'].set_color('none')

ax.spines['right'].set_color('none')

ax.spines['top'].set_color('none')

ax.set_xticks([])

ax.set_yticks([])

# 实现功能

theta = np.arange(0, 2 * np.pi, 2 * np.pi / 100)

theta = np.append(theta, [2 * np.pi])

x = np.cos(theta)

y = np.sin(theta)

v = np.linspace(0, 10, 100)

for r in v:

x1 = r * x

y1 = r * y

plt.plot(x1, y1)

plt.show()

03

import numpy as np

import matplotlib.pyplot as plt

from matplotlib import colors

# 该行用于设置chart 的样式,可以注掉

plt.style.use("mystyle")

fig = plt.figure(figsize=(8,8))

ax = fig.add_subplot(111)

ax.spines['left'].set_color('none')

ax.spines['bottom'].set_color('none')

ax.spines['right'].set_color('none')

ax.spines['top'].set_color('none')

ax.set_xticks([])

ax.set_yticks([])

theta = np.arange(0, 2 * np.pi, 2 * np.pi / 1000)

theta = np.append(theta, [2 * np.pi])

v = np.linspace(0, 10, 10)

mx = np.max(theta)

for tha in theta:

x1 = v * np.cos(tha)

y1 = v * np.sin(tha)

c = tha / mx

plt.plot(x1, y1,color=(x1[0], c, y1[0]))

plt.show()

End

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值