I think a scatter
plot is perfectly suitable to create this kind of categorical bubble plot.
Create the dataframe:
import pandas as pd
df = pd.DataFrame([[.3,.2,.4],[.1,.4,.1]], columns=list("ABC"), index=list("XY"))
Option 1: unstack the DataFrame
dfu = df.unstack().reset_index()
dfu.columns = list("XYS")
This creates a table like
X Y S
0 A X 0.3
1 A Y 0.1
2 B X 0.2
3 B Y 0.4
4 C X 0.4
5 C Y 0.1
which you can plot column-wise. Since the sizes of scatters are points one would need to multiply the S
column with some large number, like 5000 to get large bubbles.
import matplotlib.pyplot as plt
dfu["S"] *= 5000
plt.scatter(x="X", y="Y", s="S", data=dfu)
plt.margins(.4)
plt.show()
Option 2: create grid
Using e.g. numpy, one may create a grid of the dataframe's columns and index such that one may then plot a scatter of the flattened grid. Again one would need to multiply the dataframe values by some large number.
import numpy as np
import matplotlib.pyplot as plt
x,y = np.meshgrid(df.columns, df.index)
df *= 5000
plt.scatter(x=x.flatten(), y=y.flatten(), s=df.values.flatten())
plt.margins(.4)
plt.show()
In both cases the result would look like
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…