Note
Click here to download the full example code
07. Plot Parallel with dengue
This example plots a parallel graph.
9 import plotly.graph_objects as go
10
11 import numpy as np
12 import pandas as pd
13 from pandas.api.types import is_string_dtype
14 from pandas.api.types import is_numeric_dtype
15
16 from plotly.io import show
17
18 try:
19 __file__
20 TERMINAL = True
21 except:
22 TERMINAL = False
23
24
25 def load_gridsearch_sklearn_iris():
26 """This method..."""
27 # Define datapath
28 FILEPATH = './data/sklearn-gridsearch/ls2d-iris.csv'
29 # Load data
30 df = pd.read_csv(FILEPATH)
31 # Columns
32 columns = [
33 ('mean_train_spearman', 'Spearman'),
34 ('mean_train_pearson', 'Pearson'),
35 ('param_sae__max_epochs', 'Max Epochs'),
36 ('param_sae__lr', 'Learning Rate'),
37 ('mean_train_procrustes', 'Procrustes'),
38 ('mean_train_calinski_target', 'Calinski'),
39 ('mean_train_davies_b_target', 'Davies'),
40 #('param_sae__module__layers', 'Layers')
41 ]
42 # Line
43 line = dict(color=df.mean_train_calinski_target,
44 colorscale='Electric',
45 showscale=True,
46 cmin=df.mean_train_calinski_target.min(),
47 cmax=df.mean_train_calinski_target.max())
48 # Return
49 return df, line, columns
50
51
52
53 def load_raw_dengue():
54 """This method..."""
55 # Define datapath
56 FILEPATH = '../../datasets/dengue-htd-dataset/combined.csv'
57 # Load data
58 df = pd.read_csv(FILEPATH)
59 # Columns
60 columns = [
61 ('age', 'Age'),
62 ('body_temperature', 'Body Temperature'),
63 ('weight', 'Weight'),
64 ('plt', 'Platelets'),
65 ('haematocrit_percent', 'Haematocrit')
66 ]
67 # Line
68 line = dict(color=df.haematocrit_percent,
69 colorscale='Electric',
70 showscale=True,
71 cmin=df.haematocrit_percent.min(),
72 cmax=df.haematocrit_percent.max())
73 # Return
74 return df, line, columns
75
76 def create_dimension(s):
77 """This method creates the dimesions.
78
79 Dimension: numeric
80 dict(range = [32000,227900],
81 constraintrange = [100000,150000],
82 label = "Block Height",
83 values = df['blockHeight'])
84
85 Dimension: enumerated
86 dict(tickvals = [0,0.5,1,2,3],
87 ticktext = ['A','AB','B','Y','Z'],
88 label = 'Cyclinder Material',
89 values = df['cycMaterial'],
90 visible = True)
91 """
92 if is_numeric_dtype(s):
93 return dict(
94 range=[s.min(), s.max()],
95 constraintrange=[s.min(), s.max()],
96 label=s.name, values=s)
97 if is_string_dtype(s):
98 s = s.apply(str)
99 return dict(tickvals=np.arange(s.nunique()),
100 ticktext=sorted(s.unique()),
101 label=s.name, values=s)
102
103
104 # Load data
105 df, line, columns = load_raw_dengue()
106 #df, columns = load_gridsearch_sklearn_iris()
107
108 # Show
109 fig = go.Figure(data=
110 go.Parcoords(line=line,
111 dimensions=[create_dimension(df[name])
112 for name, label in columns]
113 ))
114
115
116 # Show
117 show(fig)
Total running time of the script: ( 0 minutes 3.885 seconds)