|
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,5 +113,59 @@ def horizontal_bar_chart(df, color): |
111 | 113 | fig['layout'].update(height=1200, width=900, paper_bgcolor='rgb(233,233,233)', title="Word Count Plots") |
112 | 114 | py.iplot(fig, filename='word-plots') |
113 | 115 |
|
| 116 | +<<<<<<< HEAD |
114 | 117 | return fig |
115 | 118 |
|
| 119 | +======= |
| 120 | +def sunburst(df, interior:str, exterior:str, col_num:str, title:str): |
| 121 | + ''' |
| 122 | + 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 |
| 123 | + the exterior is for columns which have more values. |
| 124 | +
|
| 125 | + Parameters |
| 126 | + ---------- |
| 127 | + df -> dataframe we are working with |
| 128 | + interior -> recommended for columns which have two or so uniques values. Must be 'str' |
| 129 | + exterior -> recommended for columns which have more values, because the graph has more space than inside. Must be 'str' |
| 130 | + 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' |
| 131 | + title -> the title we want to show in the pie, must be 'str' |
| 132 | +
|
| 133 | + Return |
| 134 | + ---------- |
| 135 | +
|
| 136 | + Return a pie chart with two levels, interior and exterior. |
| 137 | + |
| 138 | + ''' |
| 139 | + |
| 140 | + fig = go.Figure() |
| 141 | + fig = px.sunburst(df, path=[interior, exterior], values=col_num, template = 'plotly_dark') |
| 142 | + fig.update_layout(width=800, height=600, title = title) |
| 143 | + fig.show() |
| 144 | + |
| 145 | +def wordcloudviz(column): |
| 146 | + import matplotlib.pyplot as plt |
| 147 | + from wordcloud import WordCloud |
| 148 | + """ |
| 149 | + Function to create a quick visualization of wordclouds in a given column of a dataframe called df. |
| 150 | +
|
| 151 | + Parameters |
| 152 | + ---------- |
| 153 | + column = name of the column of the dataframe. |
| 154 | + Input example: df['column_name'] |
| 155 | +
|
| 156 | + Return |
| 157 | + --------- |
| 158 | + A wordcloud visualization of the words in the column. |
| 159 | + """ |
| 160 | + # First, it concatenates the text in a "single" text. |
| 161 | + text = " ".join(comment for comment in column) |
| 162 | + |
| 163 | + # Creates a wordcloud visualization |
| 164 | + wordcloud = WordCloud(width=800, height=800, background_color='white').generate(text) |
| 165 | + |
| 166 | + plt.figure(figsize=(8, 8), facecolor=None) |
| 167 | + plt.imshow(wordcloud) |
| 168 | + plt.axis("off") |
| 169 | + plt.tight_layout(pad=0) |
| 170 | + plt.show() |
| 171 | +>>>>>>> 0f8d8abe7a26aac02e768b21b22a1d2e58bd6d30 |
0 commit comments