from platform import python_version
print(python_version())
3.7.12
import matplotlib.pyplot as plt
import random

One Dimension

random.seed(1234)
x = random.sample(range(1, 100), 50)
print(x)
[57, 15, 1, 12, 75, 5, 86, 89, 11, 13, 46, 31, 3, 4, 87, 45, 83, 80, 62, 79, 60, 20, 96, 24, 98, 2, 65, 63, 32, 9, 82, 70, 77, 66, 6, 35, 53, 36, 94, 42, 78, 88, 55, 23, 18, 16, 69, 90, 30, 34]
y = [0 for _ in x]
print(y)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
fig, ax = plt.subplots()
fig.set_size_inches(12,0.5)
plt.scatter(x,y)
<matplotlib.collections.PathCollection at 0x7f5a2361ae10>

fig, ax = plt.subplots()
fig.set_size_inches(12,0.5)
plt.scatter(x,y)

for grid_pt in [20,40,60,80]:
  plt.axvline(x=grid_pt, color="silver")

ax.set_xlabel("Dim #1", fontsize=15)
plt.yticks([], [])
plt.title("1D")
plt.show()

Two Dimension

random.seed(1234)
x = random.sample(range(1, 100), 50)
y = random.sample(range(1, 100), 50)
n = list(range(1, 51))
fig, ax = plt.subplots()
fig.set_size_inches(8, 8)
plt.scatter(x,y)
for grid_pt in [20,40,60,80]:
  plt.axvline(x=grid_pt, color="silver")
  plt.axhline(y=grid_pt, color="silver")

ax.set_xlabel("Dim #1", fontsize=15)
ax.set_ylabel("Dim #2", fontsize=15)
plt.title("2D", fontsize=15)
plt.show()


Three Dimension

random.seed(1234)
x = random.sample(range(1, 100), 50)
y = random.sample(range(1, 100), 50)
z = random.sample(range(1, 100), 50)
from mpl_toolkits import mplot3d
fig = plt.figure()
ax = fig.add_subplot(1,1,1, projection = "3d")

fig.set_size_inches(8, 8)
ax.scatter(x,y,z)
ax.set_xlabel("Dim #1", fontsize=15)
ax.set_ylabel("Dim #2", fontsize=15)
ax.set_zlabel("Dim #3", fontsize=15)
plt.title("2D", fontsize=15)
plt.show()


댓글남기기