My question is about plotting in a stacked bar plot the words frequency rather than numbers with labels on the bar.
Let's suppose that I have these words
Date Text Count
01/01/2020 cura 25
destra 24
fino 18
guerra 13
americani 13
02/01/2020 italia 137
turismo 112
nuovi 109
pizza 84
moda 79
created by grouping by date and aggregating by Text
, then selecting the top 5 (head(5)
):
Attempt:
(my attempt: this generates a stacked plot, but colours and labels are not what I would like to expect)
data.groupby('Date').agg({'Text': 'value_counts'}).rename(columns={'Text': 'Count'}).groupby('Date').head(5).unstack().plot(kind='bar', stacked=True)
Request:
My expected output would be a bar chart where on the x-axis there are the dates and on the y-axis the words frequency (each word on the same date should be coloured in a different way like in a stacked plot and each bar should show words and their frequency).
Example:
Please see below an example of stacked plot that it will be useful to explain what I would like to do (if it is possible).
In the bars, instead of the numbers (340, 226,...), I would like to have the name of the top words selected by that code above and their frequency. On the x-axis there will be the date that I have shown you previously, not the year (I could not find a better plot on the web). The first bar shows the top 4 words (they should be 5 but I found only a bar chart with 4 groups) and how I would like to visualise the results.
For the size of the chart, could you please keep in mind that I have 200 dates? It would be useful for visualising it.
If you would like to show me how to do it, even using another dataset, it would be great. Thank you so much in advance for the time you will spend helping me.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…