Python 画二维和三维散点同心圆

  我们利用Python先画二维的散点圆:

  我们的圆上的点,采取圆的参数方程来取。我们根据取theta的步长来决定圆上的散点的松散度。

import numpy as np
import matplotlib.pyplot as plt

r = 1.0
a, b = (0., 0.)

theta = np.arange(0, 2*np.pi, 0.3)
x = a + r * np.cos(theta)
y = b + r * np.sin(theta)

x1 = a + 2*r * np.cos(theta)
y1 = b + 2*r * np.sin(theta)



fig = plt.figure() 
axes = fig.add_subplot(111) 
plt.scatter(x, y,s = 20, marker = 'o')
plt.scatter(x1, y1,marker = 'o')

axes.axis('equal')
plt.show()

  如图所示:

Python 画二维和三维散点同心圆_第1张图片


  画三维坐标下圆的散点图。

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D



r = 1.0
a, b = (0., 0.)

theta = np.arange(0, 2*np.pi, 0.3)
x = a + r * np.cos(theta)
y = b + r * np.sin(theta)

x1 = a + 2*r * np.cos(theta)
y1 = b + 2*r * np.sin(theta)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

ax.scatter(x, y, 1.5)
ax.scatter(x1, y1, 2)
plt.show()
  如下图所示:
Python 画二维和三维散点同心圆_第2张图片


你可能感兴趣的:(python笔记)