|
7 | 7 | from collections import defaultdict |
8 | 8 | import plotly.offline as py |
9 | 9 | from wordcloud import STOPWORDS |
| 10 | +import plotly.express as px |
| 11 | + |
10 | 12 |
|
11 | 13 | 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'): |
12 | 14 | ''' |
@@ -111,3 +113,28 @@ def horizontal_bar_chart(df, color): |
111 | 113 | fig.append_trace(trace1, 1, 2) |
112 | 114 | fig['layout'].update(height=1200, width=900, paper_bgcolor='rgb(233,233,233)', title="Word Count Plots") |
113 | 115 | 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