π 곡λΆνλ μ§μ§μνμΉ΄λ μ²μμ΄μ§?
HTMLμμ Pythonμ μ¬μ©ν μ μλ PyScript (9) λ³Έλ¬Έ
HTMLμμ Pythonμ μ¬μ©ν μ μλ PyScript (9)
μ§μ§μνμΉ΄ 2022. 11. 25. 16:02<λ³Έ λΈλ‘κ·Έλ itadventrue λμ λΈλ‘κ·Έλ₯Ό μ°Έκ³ ν΄μ 곡λΆνλ©° μμ±νμμ΅λλ€ :-)>
https://itadventure.tistory.com/551
νλ!(10) - μ¨λ³ΈμΌλ‘ μμ κ·Έλν κΎΈλ―ΈκΈ°
'νλ'λ νμ΄μ€ν¬λ¦½νΈ λμ κΈ°μ μ€μλ§μ λλ€. μ§λ κ²μκΈμ μ°μ¬λλ κΈμ λλ€ - https://itadventure.tistory.com/550 νλ!(9) - μ보카λ ν맀λ κ·Έλν 'νλ'λ νμ΄μ€ν¬λ¦½νΈ λμ κΈ°μ μ€μλ§μ λλ€
itadventure.tistory.com
π μ¨λ³Έ(seaborn) λͺ¨λμ μμνλ νΈλ₯Ό μ΄μ©νμ¬ κ·Έλνλ₯Ό μμκ² κΎΈλ―ΈκΈ°
β <py-env> νκ·Έ λ΄μ seaborn λͺ¨λμ ν¬ν¨
<py-env>
- pandas
- matplotlib
- seaborn
</py-env>
β λκΈμ μ νλ λΆλΆμμ λνμ΄(numpy)λͺ¨λμ μ¬μ©
numpy λͺ¨λμ <py-env>νκ·Έ λ΄μ μ μ΄μ£Όμ§ μμλ λ¨
25000 λΆν° 60000 κΉμ§ 5000 λ§λ€ 건λλ΄ λ°°μ΄ λ§λ€ μ μμ
plt.yticks(np.arange(25000, 60000, 5000))
β 컬λ¬νλ νΈλ‘ λ§λκ·Έλν κΎΈλ―ΈκΈ°
컬λ νλ νΈλͺ μ΄ 'rainbor_r'
'rainbow_r'μ λΆμ¬μ΄ λΉ¨μ£Όλ Έμ΄νλ¨λ³΄ μμΌλ‘ λμ€κ³ , 'rainbow' νλ νΈλ₯Ό μ¬μ©νλ©΄ μμ
plt.bar(
df_group.index.to_list(),
df_group['Volume2'].to_list(),
color=sns.color_palette(
'rainbow_r',
12
),
edgecolor='black'
)
β κ° λ§λμ κ²μ μ κ²½κ³μ μ μΆκ° -> edgecolor='black'
plt.bar(
df_group.index.to_list(),
df_group['Volume2'].to_list(),
color=sns.color_palette(
'rainbow_r',
12
),
edgecolor='black'
)
β 무μ§κ° μμμ 7κ°μ§μ΄μ§λ§ 12λ¨κ³λ‘ μμ λλκΈ°
12λ²λ§λ€ μμμ΄ λ¬΄μ§κ° μμμ΄ λλμ΄ νν
color=sns.color_palette(
'rainbow_r',
12
),
β λ°°κ²½μλ λ£κΈ°
ax = plt.gca()
ax.set_facecolor('#e8e7d2')
β μ½λ ꡬν
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
- pandas
- matplotlib
- seaborn
</py-env>
</head>
<body>
<link rel="stylesheet" href="pytable.css"/>
<py-script>
<!-- νλ₯Ό HTML νλ©΄μ μΆκ°νλ λΆλΆμ νμ΄μ¬ ν¨μλ‘ λ¨μν -->
def createElementDiv(name):
element = document.createElement('div')
element.id = name
document.body.append(element)
return Element(name)
import pandas as pd
from pyodide.http import open_url
import seaborn as sns
import numpy as np
<!-- νλ€μ€μμ csv λ₯Ό λ°μ΄ν° νλ μμΌλ‘ μ½μ΄μ΄ -->
df = pd.read_csv(open_url("http://dreamplan7.cafe24.com/pyscript/csv/avocado.csv"))
<!-- Total Volumn κ°μ 10,000μΌλ‘ λλμ΄ μλ‘μ΄ Volume2 μ΄λΌλ κ°μ μμ± (round λ₯Ό ν΅ν΄ 첫째 μ리κΉμ§ μμμ리 νμ) -->
df.insert(2, 'month', df['Date'].str[:7], True)
df.insert(5, 'Volume2',
round(df['Total Volume']/10000, 1),
True)
createElementDiv('output1').write(df)
<!-- Volume2μΌλ‘ μλ³ λ§€μΆλ μ‘°μ¬ -->
df_group = df.fillna(0).groupby('month')[['Total Volume']].sum().sort_values(by='month', ascending=True)
<!-- μλ³ λ§€μΆλ μ‘°μ¬ -->
df_group = df.fillna(0) \
.groupby('month')[['Volume2']] \
.sum() \
.sort_values(
by='month',
ascending=True
)
createElementDiv('output1').write(df_group)
<!-- μ보카λ κ·Έλν 기리기 -->
import matplotlib.pyplot as plt
<!-- κ·Έλν ν¬κΈ° μ‘°μ -->
fig = plt.figure(figsize=(15, 10))
plt.title('Month Avocado sales');
<!-- κΈμ¨λ₯Ό 45λ νμ -->
plt.xticks(rotation=45)
<!-- μλ λ³νλ₯Ό νμ€ν 보기 μν΄ 2μ΅ 5μ²λ§λΆν° μμν΄μ 6μ΅κΉμ§ YμΆμ μ§μ -->
plt.ylim(25000, 60000)
<!-- yμΆμ λκΈμ μ§μ -->
plt.yticks(np.arange(25000, 60000, 5000))
<!-- # λ§λ κ·Έλν -->
plt.bar(
df_group.index.to_list(),
df_group['Volume2'].to_list(),
color=sns.color_palette(
'rainbow_r',
12
),
edgecolor='black'
)
plt.xlabel('Year/Month')
plt.ylabel('Sales(units:10000)')
ax = plt.gca()
ax.set_facecolor('#e8e7d2')
<!-- 그리λλΌλ μλ΄μ μ μΆκ° -->
plt.grid()
fig
</py-script>
</body>
</html>
'π©βπ» λ°±μλ(Back-End) > Node js' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
HTMLμμ Pythonμ μ¬μ©ν μ μλ PyScript (11) (0) | 2022.11.25 |
---|---|
HTMLμμ Pythonμ μ¬μ©ν μ μλ PyScript (10) (1) | 2022.11.25 |
HTMLμμ Pythonμ μ¬μ©ν μ μλ PyScript (8) (0) | 2022.11.25 |
HTMLμμ Pythonμ μ¬μ©ν μ μλ PyScript (7) (0) | 2022.11.25 |
HTMLμμ Pythonμ μ¬μ©ν μ μλ PyScript (6) (0) | 2022.11.25 |