lundi 25 septembre 2023

Wordcloud centralize and reduce overlap in randomly positioned words inside a plot

import plotly
import random
import plotly.graph_objects as go
from plotly.subplots import make_subplots    

words = ['potato','hello','juvi']
colors = [plotly.colors.DEFAULT_PLOTLY_COLORS[random.randrange(1, 10)] for i in range(20)]
weights = [110,80,20]

data = go.Scatter(x=[random.random() for i in range(20)],
             y=[random.random() for i in range(20)],
             mode='text',
             text=words,
             marker={'opacity': 0.3},
             textfont={'size': weights,
                       'color': colors})

layout = go.Layout({'xaxis': {'showgrid': False, 'showticklabels': False, 'zeroline': False},
                'yaxis': {'showgrid': False, 'showticklabels': False, 'zeroline': False}})
fig = go.Figure(data=[data], layout=layout)

fig.show()

I have the following sample code which generates a wordcloud in plotly, the thing is as you can see the words tend to get out of the given square in the plot any ideas on how I could keep the words inside the blueish square. Or at least more to the center of it

enter image description here




Aucun commentaire:

Enregistrer un commentaire