In [3]:
import matplotlib.pyplot as plt
import pandas as pd
data = {
''''X'''': [1, 2, 3, 4, 5],
''''Y'''': [10, 15, 20, 25, 30],
''''BubbleSize'''': [100, 200, 300, 400, 500]
}
df = pd.DataFrame(data)
plt.scatter(''''X'''', ''''Y'''', s=''''BubbleSize'''', alpha=0.5, data=df)
plt.xlabel(''''X'''')
plt.ylabel(''''Y'''')
plt.title(''''Bubble Plot with Matplotlib'''')
plt.show()
In [4]:
import matplotlib.pyplot as plt
series1 = {''''x'''': [1, 2, 3], ''''y'''': [10, 20, 30], ''''sizes'''': [100, 200, 300], ''''label'''': ''''Series 1''''}
series2 = {''''x'''': [3, 3, 4], ''''y'''': [15, 25, 35], ''''sizes'''': [150, 125, 50], ''''label'''': ''''Series 2''''}
series3 = {''''x'''': [2, 8, 2], ''''y'''': [12, 19, 12], ''''sizes'''': [250, 150, 95], ''''label'''': ''''Series 3''''}
series4 = {''''x'''': [6, 8, 14], ''''y'''': [15, 12, 13], ''''sizes'''': [250, 50, 145], ''''label'''': ''''Series 4''''}
series5 = {''''x'''': [7, 3, 12], ''''y'''': [1, 15, 15], ''''sizes'''': [250, 350, 165], ''''label'''': ''''Series 5''''}
fig, ax = plt.subplots()
ax.scatter(series1[''''x''''], series1[''''y''''], s=series1[''''sizes''''], alpha=0.5, label=series1[''''label''''])
ax.scatter(series2[''''x''''], series2[''''y''''], s=series2[''''sizes''''], alpha=0.5, label=series2[''''label''''])
ax.scatter(series3[''''x''''], series3[''''y''''], s=series3[''''sizes''''], alpha=0.5, label=series3[''''label''''])
ax.scatter(series4[''''x''''], series4[''''y''''], s=series4[''''sizes''''], alpha=0.5, label=series4[''''label''''])
ax.scatter(series5[''''x''''], series5[''''y''''], s=series5[''''sizes''''], alpha=0.5, label=series5[''''label''''])
ax.set_xlabel(''''X Axis'''')
ax.set_ylabel(''''Y Axis'''')
ax.set_title(''''Bubble Chart with Multiple Series'''')
ax.legend()
plt.show()