I am trying to make a labelled bubble plot. I have specified the location of each bubble at x,y
in a df. My issue is that the plot cuts off the edges of the bubbles:
I thought I could correct this by changing the x
and y
axis limits, however this also moves the bubbles:
I have looked for solutions and tried adding ax.margins(2, 2)
but this also does not work:
I'm really interested to know why this happens? And how to fix it please? Many thanks in advance. Here is my code, including what I've tried:
x = [-0.3, 1.5, 2.3, 2, 4.3, 0, 2.9]
y = [0.94, 1.04, 1.5, 0.7, 1.3, 1.55, 1]
size = [5850, 2600, 6500, 1300, 4550, 7150, 1950]
label = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
df = pd.DataFrame({
'x': x,
'y': y,
's': size,
'label': label
})
fig, ax = plt.subplots(facecolor='w')
#plt.xlim(-2,7)
#plt.ylim(0.4,2)
#ax.margins(2, 2)
for key, row in df.iterrows():
ax.scatter(row['x'], row['y'], s=row['s']*5, alpha=.5)
ax.annotate(row['label'], xy=(row['x'], row['y']))```