Skip to content

Commit 8ff8781

Browse files
committed
2 parents 46c2dde + 4c95565 commit 8ff8781

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

toolkit/plot.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from collections import defaultdict
88
import plotly.offline as py
99
from wordcloud import STOPWORDS
10+
import plotly.express as px
11+
1012

1113
def plot_multiclass_prediction_image(df, row_index: int, X_test: Union[pd.DataFrame, np.ndarray], prediction_col: str = 'Top Prediction', label_col: str = 'Label'):
1214
'''
@@ -111,3 +113,28 @@ def horizontal_bar_chart(df, color):
111113
fig.append_trace(trace1, 1, 2)
112114
fig['layout'].update(height=1200, width=900, paper_bgcolor='rgb(233,233,233)', title="Word Count Plots")
113115
py.iplot(fig, filename='word-plots')
116+
117+
def sunburst(df, interior:str, exterior:str, col_num:str, title:str):
118+
'''
119+
This is a Plotly Graph similar to pie chart but with two levels, interior is for columns which have one or two unique values, and
120+
the exterior is for columns which have more values.
121+
122+
Parameters
123+
----------
124+
df -> dataframe we are working with
125+
interior -> recommended for columns which have two or so uniques values. Must be 'str'
126+
exterior -> recommended for columns which have more values, because the graph has more space than inside. Must be 'str'
127+
col_num -> it,s the column which we want measured, show us the quantity of each value for both column (interior and exterior), must be 'str'
128+
title -> the title we want to show in the pie, must be 'str'
129+
130+
Return
131+
----------
132+
133+
Return a pie chart with two levels, interior and exterior.
134+
135+
'''
136+
137+
fig = go.Figure()
138+
fig = px.sunburst(df, path=[interior, exterior], values=col_num, template = 'plotly_dark')
139+
fig.update_layout(width=800, height=600, title = title)
140+
fig.show()

0 commit comments

Comments
 (0)