python graph

newbieski·2022년 11월 3일
0

머신러닝

목록 보기
5/14

python으로 그래프 그리는 비슷비슷한 것을 자꾸 검색하는 것 같아서 정리해본다.

bar를 그리자

import plotly.express as px
x=[1,2,3]
y=[2,10,3]

fig = px.bar(x=x, y=y)
fig.show()

선을 그리자

import plotly.express as px
import numpy as np
x=np.arange(-10, 10, 0.1)
y=[10*i**3-0.9*i**2+200*i-50 for i in x]

fig = px.line(x=x, y=y)
fig.show()

점을 찍자

import matplotlib.pyplot as plt 
import numpy as np
x = [np.random.randint(1, 128) / np.random.randint(1, 128) for _ in range(1000)]
y = [np.random.randint(1, 128) / np.random.randint(1, 128) for _ in range(1000)]
plt.scatter(x, y)

3차원 좌표를 찍자

from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
x = [np.random.randint(1, 128) / np.random.randint(1, 128) for _ in range(1000)]
y = [np.random.randint(1, 128) / np.random.randint(1, 128) for _ in range(1000)]
z = [np.random.randint(1, 128) / np.random.randint(1, 128) for _ in range(1000)]
fig = plt.figure(figsize=(10, 10))
ax = fig.gca(projection='3d')
ax.scatter(x,y,z, marker='o', s=15, c='darkgreen')

plt.show()

참고

https://wikidocs.net/23242

profile
newbieski

0개의 댓글