Creates a word cloud visualization based on a list of countries. Args: countries (list[str]): A list of countries to be used to generate the word cloud. Returns: A JSON string containing the Plotly Express figure of the word cloud.
(countries: list[str])
| 283 | return fig.to_json() |
| 284 | |
| 285 | def create_bargraph(countries: list[str]) -> object: |
| 286 | """ |
| 287 | Creates a word cloud visualization based on a list of countries. |
| 288 | |
| 289 | Args: |
| 290 | countries (list[str]): A list of countries to be used to generate the word cloud. |
| 291 | |
| 292 | Returns: |
| 293 | A JSON string containing the Plotly Express figure of the word cloud. |
| 294 | """ |
| 295 | |
| 296 | # Count the occurrences of each country |
| 297 | country_counts = Counter(countries) |
| 298 | |
| 299 | # Get the names and counts of the countries |
| 300 | country_names = list(country_counts.keys()) |
| 301 | country_values = list(country_counts.values()) |
| 302 | |
| 303 | # Create a bar graph with the country names on the x-axis and counts on the y-axis |
| 304 | fig = go.Figure( |
| 305 | go.Bar( |
| 306 | x=country_names, |
| 307 | y=country_values, |
| 308 | hoverinfo='text', |
| 309 | hovertext=[f"Country: {country}<br>Citations: {count}" for country, count in zip(country_names, country_values)], |
| 310 | marker=dict( |
| 311 | color=country_values, |
| 312 | colorscale='RdYlGn_r', |
| 313 | showscale=True, |
| 314 | colorbar=dict( |
| 315 | title='Citations' |
| 316 | ) |
| 317 | ) |
| 318 | ) |
| 319 | ) |
| 320 | |
| 321 | fig.update_layout( |
| 322 | xaxis_title="Country of Origin", |
| 323 | yaxis_title="Citations", |
| 324 | title={ |
| 325 | 'text': "Frequently Cited Countries", |
| 326 | 'xanchor': 'center', |
| 327 | 'yanchor': 'top', |
| 328 | 'y': 0.9, |
| 329 | 'x': 0.5}, |
| 330 | plot_bgcolor='rgba(0,0,0,0)' |
| 331 | ) |
| 332 | |
| 333 | return fig.to_json() |