-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPokemon_type_dash.py
65 lines (52 loc) · 2.35 KB
/
Pokemon_type_dash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pandas as pd
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import plotly.express as px
from PIL import Image
from dash import Dash, dcc, html
from dash.dependencies import Input, Output
df = pd.read_csv('pokemon.csv')
app = Dash(__name__)
app.layout = html.Div([
html.H1('Pokemon Type Plot', style={'text-align': 'center'}),
dcc.Dropdown(id='Type',
value='bug',
options=[
{'label': 'bug', 'value': 'bug'},
{'label': 'dark', 'value': 'dark'},
{'label': 'dragon', 'value': 'dragon'},
{'label': 'electric', 'value': 'electric'},
{'label': 'fairy', 'value': 'fairy'},
{'label': 'fight', 'value': 'fight'},
{'label': 'fire', 'value': 'fire'},
{'label': 'flying', 'value': 'flying'},
{'label': 'ghost', 'value': 'ghost'},
{'label': 'grass', 'value': 'grass'},
{'label': 'ground', 'value': 'ground'},
{'label': 'ice', 'value': 'ice'},
{'label': 'normal', 'value': 'normal'},
{'label': 'poison', 'value': 'poison'},
{'label': 'psychic', 'value': 'psychic'},
{'label': 'rock', 'value': 'rock'},
{'label': 'steel', 'value': 'steel'},
{'label': 'water', 'value': 'water'},
]),
html.Br(),
dcc.Graph(id='Pokemon pic', style={'width': '50%'})
])
@app.callback(
Output(component_id='Pokemon pic', component_property='figure'),
[Input(component_id='Type', component_property='value')]
)
def update_output(Type):
dff_p = df.copy()
dff_p = dff_p[dff_p['type1'] == Type] # get the target pokemon info
df_p = dff_p[['attack', 'defense', 'speed', 'sp_attack', 'sp_defense']].copy(deep=True)
df_p['total_ability'] = df_p.apply(lambda x: x.sum(), axis=1)
df_cp = dff_p[['capture_rate']].copy(deep=True)
df_cp_ability = pd.concat([df_cp, df_p['total_ability']], axis=1)
fig = px.density_heatmap(df_cp_ability, x="capture_rate", y="total_ability", nbinsx=30, nbinsy=30)
return fig
if __name__ == '__main__':
app.run_server(debug=True)