Bappa
Bappa

Reputation: 81

Plot bubbleplot of entire dataframe with categorical x and y labels

I have a dataframe which looks something like this. I would like to plot this dataframe as a bubble map plot. x axis would represent the months (index labels), y would represent the days(column labels) and size of the bubble would be values in the dataframe.

MON TUE WED THU FRI
JAN 31 84 59 67 13
FEB 77 84 74 58 9
MAR 39 65 73 97 53
APR 100 75 63 88 25
MAY 60 76 59 21 62
JUN 25 18 59 63 91
JUL 27 7 65 82 90
AUG 55 10 47 82 64
SEP 27 55 74 45 88
OCT 58 5 42 42 11
NOV 74 77 16 1 70
DEC 87 13 83 74 57

Upvotes: 1

Views: 225

Answers (1)

mozway
mozway

Reputation: 260780

First reshape your dataframe:

df2 = (df.rename_axis('month')
         .reset_index()
         .melt(id_vars=['month'], var_name='day')
       )
>>> df2.head()
  month  day  value
0   JAN  MON     31
1   FEB  MON     77
2   MAR  MON     39
3   APR  MON    100
4   MAY  MON     60

Then, plot using seaborn.scatterplot:

import seaborn as sns
sns.scatterplot(data=df2, x='month', y='day', size='value')

seaborn bubbleplot

Upvotes: 1

Related Questions