그래프 그리기
import pandas as pd
with open('col_10k.txt', 'r', encoding='utf-8') as file:
data=file.readlines()
data[:10]
['2, 1, \n',
'3, 10, 5, 16, 8, 4, 2, 1, \n',
'4, 2, 1, \n',
'5, 16, 8, 4, 2, 1, \n',
'6, 3, 10, 5, 16, 8, 4, 2, 1, \n',
'7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, \n',
'8, 4, 2, 1, \n',
'9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, \n',
'10, 5, 16, 8, 4, 2, 1, \n',
'11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, \n']
col_nums=list(map(lambda line : line[:-3].split(","),data))
col_nums[:2]
[['2', ' 1'], ['3', ' 10', ' 5', ' 16', ' 8', ' 4', ' 2', ' 1']]
col_nums=list(map(lambda line : list(map(lambda x : int(x), line)),col_nums))
col_nums[:1]
[[2, 1]]
type(col_nums[-1][1])
int
from math import sin,cos,pi
def nums_to_point(num):
x_points=[0]
y_points=[0]
dir=0
index=1
for n in num[1:]:
if n%2==0:
dir+=pi/18
x_points.append(x_points[index-1]+sin(dir))
y_points.append(y_points[index-1]+cos(dir))
else:
dir-=pi/18
x_points.append(x_points[index-1]+sin(dir))
y_points.append(y_points[index-1]+cos(dir))
index+=1
return x_points,y_points
x_points,y_points=nums_to_point(col_nums[27])
points=[]
for line in col_nums:
points.append(nums_to_point(line))
points_1k=[] #그래프 그리는 시간 오래 걸려서 1000개만 만들기
for line in col_nums[:1000]:
points_1k.append(nums_to_point(line))
print(x_points)
print(y_points)
[0, 0.17364817766693033, 0.5156683209925991, 1.015668320992599, 1.3576884643182676, 1.8576884643182676, 2.1997086076439363, 2.6997086076439363, 3.3424962173304755, 3.8424962173304755, 4.485283827017015, 5.251328270135993, 6.117353673920431, 6.883398117039409, 7.749423520823847, 8.689116141609755, 9.673923894621963, 10.673923894621963, 11.65873164763417]
[0, 0.984807753012208, 1.9245003737981166, 2.7905257775825554, 3.730218398368464, 4.596243802152903, 5.535936422938811, 6.401961826723249, 7.168006269842227, 8.034031673626666, 8.800076116745645, 9.442863726432185, 9.942863726432185, 10.585651336118724, 11.085651336118724, 11.427671479444394, 11.601319657111324, 11.601319657111324, 11.774967834778254]
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np
plt.clf()
plt.figure(figsize=(10, 10))
for i in points_1k:
color=cm.tab10(np.random.rand())
plt.plot(i[0],i[1],color=color,linewidth=0.5)
plt.axis([1, 1000000, 1, 1000000])
plt.axis("equal")
plt.savefig("plot_1k_20angle.svg")
plt.savefig("plot_1k_20angle.png")
plt.show()
<Figure size 640x480 with 0 Axes>
짝수이면 오른쪽으로 각도를 틀고, 홀수이면 왼쪽으로 각도를 틀었다. 길이는 1만큼이다.
각도 10도, 1000까지 숫자
각도 5도, 1000까지 숫자
각도 60 이다.
각도 90이다. 예쁘다.
pi/30 도이다.
90도보다 살짝 작은 각도이다.
Last updated
Was this helpful?